What to do, assemble and collapse in dplyr?

Now I study the dplyr package in R, but hit the wall, realizing that the three functions are compute , collect and collapse - do.

I understand that dplyr does not use the data.frame type internally; instead, it stores its data in its own type tbl or tbl_df .

Then, to convert the user type back to R by default, data.frame , to use the default set of functions on data.frame , you should use collect , for example:

 batting <- tbl(lahman_sqlite(), "Batting") dim(collect(batting)) 

It returns [1] 99846 22 from 2016, and dim(batting) returns [1] NA 22 .

However, I'm not sure what the other two functions do - compute and collapse -. If you check it on ?collect , the docs say the following:

Description:

'computes the computing power of lazy tbls, leaving data to a remote source. "They also compute force calculations, but will bring the data returned to R data.frame (stored in 'tbl_df)." the collapse does not force to calculate, but reduces the complex tbl to the form that additional restrictions can be added.

What does this mean, in particular, forcing to compute lazy tlbs?


UPDATE

I would like to know what these functions do, and I would like an explanation of what it does, while others do not.

+6
source share
1 answer

From one of the dplyr vignettes :

There are three ways to force a query to be computed:

  • collect() executes the query and returns the results in R.

  • compute() executes the query and stores the results in a temporary table in the database.

  • collapse() turns a query into a table expression.

collect() is the function that you will use the most. Once you reach the set you want to use collect() to pull the data into local tbl_df (). If you know SQL, you can use compute() and collapse() to optimize performance.

If this does not help, the best choice is probably to study the source code of each function. You can see instructions on how to do this here: How to view help for the `dplyr :: collect` method?

+2
source

Source: https://habr.com/ru/post/1013656/


All Articles