### Install dtplyr Development Version Source: https://github.com/tidyverse/dtplyr/blob/main/README.md Install the latest development version of dtplyr from GitHub using the 'pak' package manager. ```r # install.packages("pak") pak::pak("tidyverse/dtplyr") ``` -------------------------------- ### Install dtplyr from CRAN Source: https://github.com/tidyverse/dtplyr/blob/main/README.md Use this command to install the stable version of dtplyr from the Comprehensive R Archive Network (CRAN). ```r install.packages("dtplyr") ``` -------------------------------- ### R Error Output from revdepcheck Source: https://github.com/tidyverse/dtplyr/blob/main/revdep/problems.md This output shows an error encountered during the 'checking examples' phase of the revdepcheck for the rFIA package. The error originates from within the package's examples and involves a chain of calls through `tidyselect` and `vctrs` packages, culminating in an out-of-bounds subscript error. ```R Running examples in ‘rFIA-Ex.R’ failed The error most likely occurred in: > ### Name: area > ### Title: Estimate land area from FIADB > ### Aliases: area > > ### ** Examples > > ## Load data from the rFIA package ... 14. │ └─tidyselect:::walk_data_tree(new, data_mask, context_mask) 15. │ └─tidyselect:::as_indices_sel_impl(...) 16. │ └─tidyselect:::as_indices_impl(...) 17. │ └─tidyselect:::chr_as_locations(x, vars, call = call, arg = arg) 18. │ └─vctrs::vec_as_location(...) 19. └─vctrs (local) ``() 20. └─vctrs:::stop_subscript_oob(...) 21. └─vctrs:::stop_subscript(...) 22. └─rlang::abort(...) Execution halted ``` -------------------------------- ### Error: Cannot supply both .before and .after in relocate() Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-colorder-relocate.md When using relocate(), you cannot specify both the .before and .after arguments simultaneously. This condition will raise an error. ```R relocate(dt, y, .before = x, .after = x) ``` -------------------------------- ### Provide 'order_by' argument for slice_min/slice_max Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-slice.md The slice_min and slice_max functions require the 'order_by' argument to be supplied. If 'order_by' is absent, an error will occur. ```R slice_min(dt) ``` ```R slice_max(dt) ``` -------------------------------- ### Print Lazy Data Table with n Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step.md Demonstrates printing a lazy data table with a specified number of rows using the `n` argument. This controls the number of rows displayed in the output. ```R dt <- letters %>% lapply(function(.x) tibble(!!.x := 1:10)) %>% bind_cols() %>% lazy_dt("DT") print(dt, n = 3) ``` -------------------------------- ### Show query for names_glue Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_wider.md Displays the generated data.table code when names_glue is used to format output column names. ```R show_query(step) ``` -------------------------------- ### Load dtplyr and dplyr Source: https://github.com/tidyverse/dtplyr/blob/main/README.md Load the necessary libraries, including data.table, dtplyr, and dplyr, to begin using dtplyr functionalities. warn.conflicts = FALSE prevents messages about conflicting function names. ```r library(data.table) library(dtplyr) library(dplyr, warn.conflicts = FALSE) ``` -------------------------------- ### Using summarise() with default .groups in dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-summarise.md Demonstrates the default behavior of summarise() when no .groups argument is specified. It shows how dtplyr translates the operation to SQL and the resulting message about grouping. ```R eval_bare(expr(lazy_dt(data.frame(x = 1, y = 2), "DT") %>% group_by(x, y) %>% dplyr::summarise() %>% show_query()), env(global_env())) ``` -------------------------------- ### rename_with generates minimal spec Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call.md Shows how `rename_with` with `toupper` generates a minimal `setnames` specification for renaming columns. This is useful for simple, direct column renaming. ```R dt %>% rename_with(toupper) %>% show_query() ``` -------------------------------- ### Print Lazy Data Table with max_footer_lines Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step.md Illustrates printing a lazy data table with a limited number of footer lines using `max_footer_lines`. This controls how many lines are shown after the main data, including row counts and variable information. ```R print(dt, max_footer_lines = 1) ``` -------------------------------- ### Group Lazy Data Table with dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step.md Demonstrates grouping a lazy data table by specified columns using `group_by()`. The output indicates that the data is grouped and shows a preview, similar to the initial lazy data table. ```R dt %>% group_by(vs, am) ``` -------------------------------- ### Print Lazy Data Table with max_extra_cols Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step.md Shows how to print a lazy data table when it has many columns, using `max_extra_cols` to limit the number of columns displayed. This is useful for wide tables. ```R print(dt, max_extra_cols = 3) ``` -------------------------------- ### Preview Transformations and Generated data.table Code Source: https://github.com/tidyverse/dtplyr/blob/main/README.md Print a lazy data table after applying dplyr verbs to preview the transformations and see the generated data.table code. This is useful for debugging. ```r mtcars2 %>% filter(wt < 5) %>% mutate(l100k = 235.21 / mpg) %>% group_by(cyl) %>% summarise(l100k = mean(l100k)) ``` -------------------------------- ### Supply exactly one of 'n' or 'prop' for slice_head Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-slice.md For the slice_head function, you must supply exactly one of the 'n' or 'prop' arguments. Providing both or neither will result in an error. ```R slice_head(dt, n = 1, prop = 1) ``` -------------------------------- ### Error in rename_with with non-function Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call.md Demonstrates an error condition when `rename_with` is provided with a non-function argument. The `.fn` argument must be a function name or formula. ```R dt %>% rename_with(1) ``` -------------------------------- ### Compute distinct computed variables Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call.md Demonstrates computing distinct values for a new variable derived from existing columns. This uses `unique` with `:=` for assignment and subsequent column removal. ```R dt %>% distinct(z = x + y) %>% show_query() ``` -------------------------------- ### Explicitly name 'n' argument for slice_*() functions Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-slice.md When using slice_*() functions like slice_head, slice_tail, slice_min, slice_max, and slice_sample, the 'n' argument must be explicitly named. Failure to do so will result in an error. ```R slice_head(dt, 5) ``` ```R slice_tail(dt, 5) ``` ```R slice_min(dt, x, 5) ``` ```R slice_max(dt, x, 5) ``` ```R slice_sample(dt, 5) ``` -------------------------------- ### Pivot wider with name repair Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_wider.md Applies pivot_wider and demonstrates the error when duplicate names are encountered without repair. It then shows how to use names_repair = "unique" to resolve these conflicts. ```R pivot_wider(df, names_from = lab, values_from = val) ``` ```R pivot_wider(df, names_from = lab, values_from = val, names_repair = "unique") ``` -------------------------------- ### rename_with with column selection Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call.md Illustrates `rename_with` used with specific column selection, generating a `setnames` call that renames a subset of columns. This allows for targeted renaming. ```R dt %>% rename_with(toupper, 1:3) %>% show_query() ``` -------------------------------- ### Error: `into` must be a character vector Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-separate.md This error is raised when the `into` argument in `separate()` is not a character vector. Verify that `into` is provided as a character type. ```R separate(dt, x, FALSE) ``` -------------------------------- ### dtplyr full_join for Cross Join Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-join.md Performs a full join that results in a cross join when `by` is an empty character vector. Use `as.data.table()`, `as.data.frame()`, or `as_tibble()` to access the results. ```r full_join(dt1, dt2, by = character()) ``` -------------------------------- ### Error Handling for Unbalanced Datasets in pivot_longer Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_longer.md This code demonstrates that `pivot_longer` will error if the dataset is unbalanced, as `data.table::melt` does not support this. Ensure your data is balanced before pivoting. ```R pivot_longer(dt, everything(), names_to = c(".value", "id"), names_sep = "_") ``` -------------------------------- ### Ensure 'prop' is a single number for slice_head Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-slice.md The 'prop' argument in slice_head must be a single number. Providing a non-numeric value or NA will cause an error. ```R slice_head(dt, prop = "a") ``` ```R slice_head(dt, prop = NA) ``` -------------------------------- ### Mutate and Compute Lazy Data Table with dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step.md Shows how to add a new column (`y = 10`) to a lazy data table using `mutate()` and then compute the result into a new table named 'DT2' using `compute()`. The output displays the new table with the added column and the underlying `data.table` code used for computation. ```R dt %>% mutate(y = 10) %>% compute("DT2") ``` -------------------------------- ### Create Lazy Data Table with dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step.md Use `lazy_dt()` to create a lazy data table from an existing data frame. The output shows the structure and a preview of the data, along with a note to use conversion functions like `as.data.table()` to access the results. ```R dt <- lazy_dt(mtcars, "DT") dt ``` -------------------------------- ### Error when selecting non-existent columns with drop_na Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call.md Highlights an error that occurs when `drop_na` attempts to select a column that does not exist in the data.table. This ensures data integrity by preventing operations on invalid columns. ```R collect(drop_na(dt, "z")) ``` -------------------------------- ### if_all() gives informative errors for invalid .fns Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval-across.md Similar to `across()`, `dtplyr::if_all()` provides informative errors when the `.fns` argument is invalid, ensuring correct usage. ```R capture_if_all(dt, if_all(a, 1)) ``` ```R capture_if_all(dt, if_all(a, list(1))) ``` -------------------------------- ### dtplyr left_join for Cross Join Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-join.md Performs a left join that results in a cross join when `by` is an empty character vector. Use `as.data.table()`, `as.data.frame()`, or `as_tibble()` to access the results. ```r left_join(dt1, dt2, by = character()) ``` -------------------------------- ### across() does not support formulas with dots Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval-across.md When using `dtplyr::across()` with a purrr-style lambda in `.fns`, `...` is not supported. Use a lambda instead or inline them. ```R capture_across(dt, across(a:b, ~ log(.x, base = .y), base = 2)) ``` ```R capture_across(dt, across(a:b, list(~ log(.x, base = .y)), base = 2)) ``` -------------------------------- ### dtplyr right_join for Cross Join Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-join.md Performs a right join that results in a cross join when `by` is an empty character vector. Use `as.data.table()`, `as.data.frame()`, or `as_tibble()` to access the results. ```r right_join(dt1, dt2, by = character()) ``` -------------------------------- ### dtplyr inner_join for Cross Join Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-join.md Performs an inner join that results in a cross join when `by` is an empty character vector. Use `as.data.table()`, `as.data.frame()`, or `as_tibble()` to access the results. ```r inner_join(dt1, dt2, by = character()) ``` -------------------------------- ### Mutate with unnamed argument Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-mutate.md Unnamed arguments in mutate are ignored. If an object is not found, an error will occur. ```R mutate(dt, y) ``` -------------------------------- ### Ensure 'n' is a single number for slice_head Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-slice.md The 'n' argument in slice_head must be a single number. Providing a non-numeric value or NA will cause an error. ```R slice_head(dt, n = "a") ``` ```R slice_head(dt, n = NA) ``` -------------------------------- ### Error: `sep` must be a character vector Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-separate.md This error occurs when the `sep` argument in `separate()` is not a character vector. Ensure `sep` is correctly specified as a character type. ```R separate(dt, x, "x", FALSE) ``` -------------------------------- ### Unsupported lag() order_by in dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval.md The `order_by` argument for the `lag()` function is not supported by dtplyr. Use with caution or consider alternative approaches. ```R The `order_by` argument of `lag()` is not supported by dtplyr ``` -------------------------------- ### Unsupported Feature: names_transform in pivot_longer Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_longer.md dtplyr does not support the `names_transform` argument in `pivot_longer`. Use this to check for unsupported arguments and ensure compatibility. ```R dt %>% pivot_longer(names_transform = list()) ``` -------------------------------- ### Unsupported Feature: names_ptypes in pivot_longer Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_longer.md dtplyr does not support the `names_ptypes` argument in `pivot_longer`. Use this to check for unsupported arguments and ensure compatibility. ```R dt %>% pivot_longer(names_ptypes = list()) ``` -------------------------------- ### Access Results as a Tibble Source: https://github.com/tidyverse/dtplyr/blob/main/README.md Convert the results of dplyr operations on a lazy data table back into a standard tibble using as_tibble(). This triggers the computation of the data.table code. ```r mtcars2 %>% filter(wt < 5) %>% mutate(l100k = 235.21 / mpg) %>% group_by(cyl) %>% summarise(l100k = mean(l100k)) %>% as_tibble() ``` -------------------------------- ### Empty select() after group_by() Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-select.md When an empty select() is applied after grouping with group_by(), dtplyr adds the grouping variables back. This behavior is consistent whether the data is copied or not. ```R out <- lz %>% group_by(x) %>% select() ``` ```R out <- lz %>% group_by(x) %>% select() ``` -------------------------------- ### Unsupported Feature: values_ptypes in pivot_longer Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_longer.md dtplyr does not support the `values_ptypes` argument in `pivot_longer`. Use this to check for unsupported arguments and ensure compatibility. ```R dt %>% pivot_longer(values_ptypes = list()) ``` -------------------------------- ### Unsupported Feature: values_transform in pivot_longer Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-call-pivot_longer.md dtplyr does not support the `values_transform` argument in `pivot_longer`. Use this to check for unsupported arguments and ensure compatibility. ```R dt %>% pivot_longer(values_transform = list()) ``` -------------------------------- ### across() gives informative errors for invalid .fns Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval-across.md dtplyr's `across()` provides informative errors when the `.fns` argument is not a NULL, function, formula, or list, or when list elements are not functions or formulas. ```R capture_across(dt, across(a, 1)) ``` ```R capture_across(dt, across(a, list(1))) ``` -------------------------------- ### Create a Lazy Data Table Source: https://github.com/tidyverse/dtplyr/blob/main/README.md Use lazy_dt() to wrap a data frame (e.g., mtcars) into a 'lazy' data table object. This object tracks subsequent dplyr operations without immediately computing them. ```r mtcars2 <- lazy_dt(mtcars) ``` -------------------------------- ### desc() argument check in dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval.md The `desc()` function in dtplyr checks for exactly one argument. Providing more than one argument will result in an error. ```R capture_dot(df, desc(a, b)) ``` -------------------------------- ### Error when using .groups = "rowwise" with summarise() in dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-summarise.md Illustrates that the .groups argument cannot be set to "rowwise" when using summarise() in dtplyr. It highlights the allowed values for .groups. ```R i Possible values are NULL (default), "drop_last", "drop", and "keep" ``` -------------------------------- ### if_all() disallows renaming variables Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval-across.md The `dtplyr::if_all()` function does not permit renaming variables within its arguments, which is enforced by an informative error. ```R expect_error(capture_if_all(dt, if_all(c(a = x, b = y)))) ``` -------------------------------- ### Error with where() in dtplyr Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/tidyeval.md The tidyselect interface for `where()` is not supported by dtplyr, leading to errors. This is due to limitations in predicate support. ```R This tidyselect interface doesn't support predicates. ``` ```R This tidyselect interface doesn't support predicates. ``` -------------------------------- ### dtplyr count() with invalid name Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/count.md When using count() with a non-string value for the name argument, an error is raised. Ensure the name is a character string. ```R dt %>% count(name = 10) %>% collect() ``` -------------------------------- ### Named Input Error in dtplyr Filter Source: https://github.com/tidyverse/dtplyr/blob/main/tests/testthat/_snaps/step-subset-filter.md This error occurs when a named argument is used in the filter function instead of a comparison. Ensure you use '==' for comparisons. ```R filter(dt, x = 1) ``` ```R filter(dt, y > 1, x = 1) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.