### R Package Installation Status: OK Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md Indicates that a package passed all checks during installation and testing. This is the expected outcome for a successful installation. ```text * checking Rd contents ... OK * checking for unstated dependencies in examples ... OK * checking line endings in C/C++/Fortran sources/headers ... OK * checking compiled code ... OK * checking examples ... OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... OK Running ‘testthat.R’ * DONE Status: OK ``` -------------------------------- ### Package Installation Failure Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md Indicates that a package failed to install. Check the installation log for details. ```text Installation failed. See ‘/tmp/workdir/bayesdfa/new/bayesdfa.Rcheck/00install.out’ for details. ``` -------------------------------- ### Signac Installation Check (Devel) Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This output shows a successful installation check for the 'Signac' package in its development version. It confirms that the package can be installed without errors. ```text * using log directory ‘/tmp/workdir/Signac/new/Signac.Rcheck’ * using R version 4.5.1 (2025-06-13) * using platform: x86_64-pc-linux-gnu * R was compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 GNU Fortran (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 * running under: Ubuntu 24.04.3 LTS * using session charset: UTF-8 * using option ‘--no-manual’ * checking for file ‘Signac/DESCRIPTION’ ... OK ... * checking for GNU extensions in Makefiles ... OK * checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK * checking use of PKG_*FLAGS in Makefiles ... OK * checking compiled code ... OK * checking examples ... OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... OK Running ‘testthat.R’ * DONE Status: OK ``` -------------------------------- ### Signac Installation Check (CRAN) Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This output indicates a successful installation check for the 'Signac' package in its CRAN version. It confirms that the package installs correctly. ```text * using log directory ‘/tmp/workdir/Signac/old/Signac.Rcheck’ * using R version 4.5.1 (2025-06-13) * using platform: x86_64-pc-linux-gnu * R was compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 GNU Fortran (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 * running under: Ubuntu 24.04.3 LTS * using session charset: UTF-8 * using option ‘--no-manual’ * checking for file ‘Signac/DESCRIPTION’ ... OK ... * checking for GNU extensions in Makefiles ... OK * checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK * checking use of PKG_*FLAGS in Makefiles ... OK * checking compiled code ... OK * checking examples ... OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... OK Running ‘testthat.R’ * DONE Status: OK ``` -------------------------------- ### Install vctrs from CRAN Source: https://github.com/r-lib/vctrs/blob/main/README.md Standard installation of the vctrs package from CRAN. ```r install.packages("vctrs") ``` -------------------------------- ### Install vctrs Development Version Source: https://github.com/r-lib/vctrs/blob/main/README.md Installation of the development version of vctrs using the pak package. ```r # install.packages("pak") pak::pak("r-lib/vctrs") ``` -------------------------------- ### R Package Installation Error: Missing Dependency Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md Occurs during package installation when a required dependency, such as 'rstantools', is not found. This prevents the package from being configured and installed. ```text ** package ‘bayesdfa’ successfully unpacked and MD5 sums checked ** using staged installation Error in loadNamespace(x) : there is no package called ‘rstantools’ Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted ERROR: configuration failed for package ‘bayesdfa’ * removing ‘/tmp/workdir/bayesdfa/new/bayesdfa.Rcheck/bayesdfa’ ``` -------------------------------- ### R Package Installation Failure Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This generic installation failure message indicates that the R package 'rshift' could not be installed. The specific details of the failure can be found in the installation log file. ```text * checking whether package ‘rshift’ can be installed ... ERROR Installation failed. See ‘/tmp/workdir/rshift/new/rshift.Rcheck/00install.out’ for details. ``` -------------------------------- ### Setup data for row-binding benchmark Source: https://github.com/r-lib/vctrs/blob/main/bench/rbind.md Initializes a data frame and creates a list of data frames for benchmarking. Ensure `tidyverse` and `vctrs` are loaded. ```r library(tidyverse) library(vctrs) df <- data.frame(x = 1:10, y = letters[1:10], stringsAsFactors = FALSE) dfs <- map(1:100, ~ df) ``` -------------------------------- ### Load vctrs and other libraries Source: https://github.com/r-lib/vctrs/blob/main/bench/sorting-vs-hashing.md Loads necessary R libraries for benchmarking and data manipulation. Ensure these libraries are installed before running. ```r library(vctrs) library(rlang) library(stringr) library(ggplot2) library(dplyr) ``` -------------------------------- ### TriDimRegression Installation Failure Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This snippet shows an installation error for the 'TriDimRegression' package. The error message indicates that the installation failed and directs the user to a log file for details. ```text * checking whether package ‘TriDimRegression’ can be installed ... ERROR Installation failed. See ‘/tmp/workdir/TriDimRegression/new/TriDimRegression.Rcheck/00install.out’ for details. ``` -------------------------------- ### Check type compatibility in `vec_interval_locate_containers` Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/interval.md Ensures that the `start` and `end` arguments in `vec_interval_locate_containers` have compatible types. ```R (expect_error(vec_interval_locate_containers(1, "x"))) ``` -------------------------------- ### Input is tidy recycled Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/type-data-frame.md This example shows that `data_frame()` performs tidy recycling, and an error is raised if the recycling is incompatible. ```R expect_error(data_frame(1:2, 1:3), class = "vctrs_error_incompatible_size") ``` -------------------------------- ### R Package Installation Failure: Missing Dependency (CRAN) Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md Occurs during package installation from CRAN when a required dependency, such as 'rstantools', is not found. This prevents the package from being configured and installed. ```text ** package ‘bayesdfa’ successfully unpacked and MD5 sums checked ** using staged installation Error in loadNamespace(x) : there is no package called ‘rstantools’ Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted ERROR: configuration failed for package ‘bayesdfa’ * removing ‘/tmp/workdir/bayesdfa/old/bayesdfa.Rcheck/bayesdfa’ ``` -------------------------------- ### Casting with Named Arguments Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/cast.md Demonstrates casting with named arguments for 'x' and 'to'. This example shows an error when the types of the named arguments do not match. ```R vec_cast(1, "", x_arg = "foo", to_arg = "bar") ``` -------------------------------- ### Error in nswgeo examples related to sf and vctrs Source: https://github.com/r-lib/vctrs/blob/main/revdep/problems.md Examples in the nswgeo package are failing due to an error originating from `vctrs::vec_c` when called within the `sf` package's `st_sfc` function. This suggests an issue with how `sf` handles the combination of different geometry types or structures when attempting to concatenate them using vctrs. ```R 5. │ └─ggplot2:::by_layer(...) 6. │ ├─rlang::try_fetch(...) 7. │ │ ├─base::tryCatch(...) 8. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers) 9. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) 10. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler) 11. │ │ └─base::withCallingHandlers(...) 12. │ └─ggplot2 (local) f(l = layers[[i]], d = data[[i]]) 13. │ └─l$compute_geom_2(d, theme = plot@theme) 14. │ └─ggplot2 (local) compute_geom_2(..., self = self) 15. │ └─ggproto_parent(Layer, self)$compute_geom_2(data, params, ...) 16. │ └─ggplot2 (local) compute_geom_2(..., self = self) 17. │ └─self$geom$use_defaults(...) 18. │ └─ggplot2 (local) use_defaults(..., self = self) 19. │ └─vctrs::vec_c(points, lines, others, collections) 20. │ └─vctrs (local) ``() 21. │ ├─vctrs:::vec_restore_dispatch(x = x, to = to) 22. │ └─sf:::vec_restore.sfc(x = x, to = to) 23. │ └─sf::st_sfc(x, crs = st_crs(to), precision = st_precision(to)) 24. └─base::.handleSimpleError(...) 25. └─rlang (local) h(simpleError(msg, call)) 26. └─handlers[[1L]](cnd) 27. └─cli::cli_abort(...) 28. └─rlang::abort(...) Execution halted ``` -------------------------------- ### R Package Installation Error: Missing Dependencies Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This error occurs when an R package fails to install because required dependencies ('loon', 'loon.ggplot') are not available in the current R environment. This is a common issue when building packages from source. ```text * checking package dependencies ... ERROR Packages required but not available: 'loon', 'loon.ggplot' See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’ manual. * DONE Status: 1 ERROR ``` -------------------------------- ### list_of() with .ptype and .size arguments Source: https://github.com/r-lib/vctrs/blob/main/NEWS.md Shows how to use the .ptype and .size arguments in list_of() to restrict element type and size, including examples where only type, only size, or both are restricted. ```r # Restricts the element type, but not the size (default behavior) list_of(1:2, 3:4, .ptype = integer(), .size = zap()) # Restricts the element size, but not the type list_of(1:2, 3:4, .ptype = zap(), .size = 2) # Restricts the element type and size list_of(1:2, 3:4, .ptype = integer(), .size = 2) ``` -------------------------------- ### Backwards compatibility for vec_chop(x, 1) Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md This example demonstrates the backwards compatible behavior of `vec_chop(x, 1)` which now correctly errors, indicating that `indices` must be a list. ```R vec_chop(1:2, 1) ``` -------------------------------- ### Check type compatibility in `vec_interval_locate_groups` Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/interval.md Ensures that the `start` and `end` arguments in `vec_interval_locate_groups` have compatible types. ```R (expect_error(vec_interval_locate_groups(1, "x"))) ``` -------------------------------- ### Casting Factor to Double Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/cast.md An example of casting a factor to a double, which results in an incompatible type error. ```R vec_cast(factor("foo"), 10) ``` -------------------------------- ### Backwards compatibility for vec_chop(x, indices, sizes) Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md This example shows the error when `vec_chop` is called with positional arguments that would have been valid in older versions but are now disallowed. ```R vec_chop(1, list(1), 2) ``` -------------------------------- ### Backwards compatibility for vec_chop(x, indices, indices) Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md This example demonstrates an error when `vec_chop` is called with a repeated positional argument that is now disallowed. ```R vec_chop(1, list(1), indices = list(1)) ``` -------------------------------- ### List Combine with Custom Class and NULL Index Error Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/list-combine.md Similar to the previous example, this shows an error when using a custom class ('foobar') with NULL indices, resulting in an attempt to subset past the end of the list. ```r list_combine(x_foobar, indices = indices, size = size, default = default_foobar, unmatched = unmatched, multiple = multiple, slice_x = slice_x, ptype = ptype, name_spec = name_spec, name_repair = name_repair, x_arg = x_arg, indices_arg = indices_arg, default_arg = default_arg) ``` -------------------------------- ### Handle NULL elements with list_check_all_size Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md The `list_check_all_size()` function can optionally allow NULL elements when `allow_null = TRUE`. This example shows an error when an element is not of the expected size, even with `allow_null` enabled. ```r list_check_all_size(x, size = 1) ``` ```r list_check_all_size(x, size = 1, allow_null = TRUE) ``` -------------------------------- ### List Combine with Custom Class 'c' and NULL Index Error Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/list-combine.md This example illustrates the same NULL index subsetting error as the previous ones, but with a different custom class ('foobar_c'). The underlying issue remains trying to access an element beyond the list's bounds. ```r list_combine(x_foobar_c, indices = indices, size = size, default = default_foobar_c, unmatched = unmatched, multiple = multiple, slice_x = slice_x, ptype = ptype, name_spec = name_spec, name_repair = name_repair, x_arg = x_arg, indices_arg = indices_arg, default_arg = default_arg) ``` -------------------------------- ### vec_as_short_length() Error: String Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() expects a number. This example shows the error when a string is provided. ```R (expect_error(my_function("foo"))) ``` -------------------------------- ### Vector Prototype and Casting Operations in vctrs Source: https://github.com/r-lib/vctrs/blob/main/README.md Illustrates common vector prototype and casting operations, showing how different data types are handled. Requires loading the vctrs library. ```r library(vctrs) # Prototypes vec_ptype_common(FALSE, 1L, 2.5) #> numeric(0) str(vec_cast_common(FALSE, 1L, 2.5)) #> List of 3 #> $ : num 0 #> $ : num 1 #> $ : num 2.5 ``` -------------------------------- ### Benchmark Integer Sorting (Small Size) Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Sets up and runs benchmarks for vec_order() and base_order() on integer vectors with varying sizes and group counts. ```r set.seed(123) size <- 10 ^ (1:4) n_groups <- 10 ^ (1:6) df <- bench::press( size = size, n_groups = n_groups, { x <- sample(n_groups, size, replace = TRUE) bench::mark(vec_order(x), base_order(x), iterations = 50) } ) ``` -------------------------------- ### List Combine with Explicit Ptype for Type Coercion Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/list-combine.md Demonstrates how specifying a `ptype` can override the common type inference and attempt type coercion. This example shows a lossy conversion error when coercing from double to integer. ```R list_combine(x, indices = indices, size = 2, ptype = integer()) ``` -------------------------------- ### Create a new S3 vector class with new_vctr() Source: https://context7.com/r-lib/vctrs/llms.txt Use `new_vctr()` to create custom S3 vector classes. This example defines a 'percent' class wrapping a double, including custom formatting and coercion methods for seamless integration with other numeric types. ```r library(vctrs) # Define a "percent" class wrapping a double new_percent <- function(x = double()) { stopifnot(is.double(x)) new_vctr(x, class = "percent") } # Custom formatting format.percent <- function(x, ...) { paste0(formatC(unclass(x) * 100, digits = 1, format = "f"), "%”) } # Coercion methods (so percent combines sensibly with double) vec_ptype2.percent.percent <- function(x, y, ...) new_percent() vec_ptype2.percent.double <- function(x, y, ...) double() vec_ptype2.double.percent <- function(x, y, ...) double() vec_cast.percent.percent <- function(x, to, ...) x vec_cast.percent.double <- function(x, to, ...) new_percent(x) vec_cast.double.percent <- function(x, to, ...) unclass(x) p <- new_percent(c(0.1, 0.2, 0.5)) p #> [1] 10.0% 20.0% 50.0% p[1:2] #> [1] 10.0% 20.0% (attributes restored) vec_c(p, 0.3) #> [1] 0.1 0.2 0.5 0.3 (common type: double) p > new_percent(0.15) #> [1] FALSE TRUE TRUE ``` -------------------------------- ### Benchmark Integer Sorting (Large Size) Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Sets up and runs benchmarks for vec_order() and base_order() on large integer vectors with varying sizes and group counts. ```r set.seed(123) size <- 10 ^ (5:7) n_groups <- 10 ^ (1:6) df <- bench::press( size = size, n_groups = n_groups, { x <- sample(n_groups, size, replace = TRUE) bench::mark(vec_order(x), base_order(x), iterations = 10) } ) ``` -------------------------------- ### TriDimRegression Package Installation Failure (Devel) Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This error occurs during the development installation of the 'TriDimRegression' package, indicating a missing dependency on 'rstantools'. ```text * installing *source* package ‘TriDimRegression’ ... ** this is package ‘TriDimRegression’ version ‘1.0.3’ ** package ‘TriDimRegression’ successfully unpacked and MD5 sums checked ** using staged installation Error in loadNamespace(x) : there is no package called ‘rstantools’ Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted ERROR: configuration failed for package ‘TriDimRegression’ * removing ‘/tmp/workdir/TriDimRegression/new/TriDimRegression.Rcheck/TriDimRegression’ ``` -------------------------------- ### List Combine with Type Failure (int, int, dbl) Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/list-combine.md Illustrates a type failure when combining two integer vectors and a double vector. Similar to the previous example, this error arises from incompatible attributes when a custom class is involved. ```r list_combine(list(int, int, dbl), indices = list(1, 2, 3), size = 3) ``` -------------------------------- ### TriDimRegression Package Installation Failure (CRAN) Source: https://github.com/r-lib/vctrs/blob/main/revdep/failures.md This error is observed during the CRAN installation of the 'TriDimRegression' package, highlighting a failure to load a required package, 'rstantools'. ```text * installing *source* package ‘TriDimRegression’ ... ** this is package ‘TriDimRegression’ version ‘1.0.3’ ** package ‘TriDimRegression’ successfully unpacked and MD5 sums checked ** using staged installation Error in loadNamespace(x) : there is no package called ‘rstantools’ Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted ERROR: configuration failed for package ‘TriDimRegression’ * removing ‘/tmp/workdir/TriDimRegression/old/TriDimRegression.Rcheck/TriDimRegression’ ``` -------------------------------- ### List Combine with NULL Index Error Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/list-combine.md This example demonstrates an error when attempting to subset elements past the end of a list using NULL indices. It highlights that location 2 does not exist when the list only has 1 element. ```r list_combine(x, indices = indices, size = size, default = default, unmatched = unmatched, multiple = multiple, slice_x = slice_x, ptype = ptype, name_spec = name_spec, name_repair = name_repair, x_arg = x_arg, indices_arg = indices_arg, default_arg = default_arg) ``` -------------------------------- ### list_check_all_vectors() with environment input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md Shows how list_check_all_vectors() errors when an environment is passed as an argument, expecting a list. ```R my_function <- (function(my_arg) list_check_all_vectors(my_arg)) (expect_error(my_function(env()))) ``` -------------------------------- ### Different quiet repair strategies Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/names.md Compares the output of `vec_as_names()` with 'unique_quiet' and 'universal_quiet' repair strategies, both with `quiet = TRUE` and `quiet = FALSE`. ```R vec_as_names(c("1", "1"), repair = "unique_quiet") ``` ```R vec_as_names(c("1", "1"), repair = "universal_quiet") ``` ```R vec_as_names(c("1", "1"), repair = "unique_quiet", quiet = TRUE) ``` ```R vec_as_names(c("1", "1"), repair = "universal_quiet", quiet = TRUE) ``` ```R vec_as_names(c("1", "1"), repair = "unique_quiet", quiet = FALSE) ``` ```R vec_as_names(c("1", "1"), repair = "universal_quiet", quiet = FALSE) ``` -------------------------------- ### List Combine with Custom Class Incompatibility (Variant) Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/list-combine.md Another example of combining custom vctrs classes with incompatible attributes, similar to the previous case, emphasizing the need for proper vctrs method implementation. ```R list_combine(x_foobar_c, indices = indices, size = size, default = default_foobar_c, unmatched = unmatched, multiple = multiple, slice_x = slice_x, ptype = ptype, name_spec = name_spec, name_repair = name_repair, x_arg = x_arg, indices_arg = indices_arg, default_arg = default_arg) ``` -------------------------------- ### list_all_vectors() errors on environments Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md list_all_vectors() requires a list as input and will error if an environment is provided. ```R (expect_error(list_all_vectors(env()))) ``` -------------------------------- ### vec_c() ignoring names with zap() Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/c.md Demonstrates how to ignore outer names in vec_c() by providing `.name_spec = zap()`. This example results in an error due to incompatible types between character and double. ```R (expect_error(vec_c(a = c(b = letters), b = 1, .name_spec = zap()), class = "vctrs_error_incompatible_type") ) ``` -------------------------------- ### Benchmark: Multiple Integer Columns Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Compares `vec_order()` and `base_order()` on a data frame with 20 integer columns, each having only 2 groups. This tests performance with many columns and few distinct values per column. ```r set.seed(123) size <- 1e6L n_groups <- 2 n_cols <- 20 cols <- replicate(n_cols, sample(n_groups, size, TRUE), simplify = FALSE) names(cols) <- seq_along(cols) df <- vctrs::new_data_frame(cols, size) bench::mark(vec_order(df), base_order(df), iterations = 10) #> # A tibble: 2 x 6 #> expression min median `itr/sec` mem_alloc `gc/sec` #> #> 1 vec_order(df) 200ms 204ms 4.86 19.84MB 0.539 #> 2 base_order(df) 188ms 198ms 5.07 3.82MB 0 ``` -------------------------------- ### vec_as_short_length() Error: NULL Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() expects a number. This example shows the error when NULL is provided. ```R (expect_error(my_function(foobar(1:2)))) ``` -------------------------------- ### Create record-style S3 vector classes with new_rcrd() Source: https://context7.com/r-lib/vctrs/llms.txt Use `new_rcrd()` to create record-style vectors, which store multiple fields internally. This example defines a 'rational number' class with 'num' and 'den' fields, demonstrating custom formatting and field access/modification. ```r library(vctrs) # Define a "rational number" record class new_rational <- function(num = integer(), den = integer()) { stopifnot(is.integer(num), is.integer(den)) new_rcrd(list(num = num, den = den), class = "rational") } format.rational <- function(x, ...) { paste0(field(x, "num"), "/", field(x, "den")) } r <- new_rational(c(1L, 2L, 3L), c(2L, 3L, 4L)) r #> [1] 1/2 2/3 3/4 vec_size(r) #> [1] 3 # Access individual fields field(r, "num") #> [1] 1 2 3 field(r, "den") #> [1] 2 3 4 fields(r) #> [1] "num" "den" n_fields(r) #> [1] 2 # Modify a field (returns new object) field(r, "den") <- c(3L, 4L, 5L) # Slicing preserves all fields r[c(1, 3)] #> [1] 1/3 3/5 ``` -------------------------------- ### Handle Max 8 Version Components with `vec_proxy_equal` Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/type-misc.md The `vec_proxy_equal()` function has a limitation on the number of version components it can handle. Ensure your version data does not exceed 8 components to avoid errors. ```R vec_proxy_equal(x) ``` -------------------------------- ### vec_as_short_length() Error: Number Too Large Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() has a maximum value for numbers. This example shows the error when the number is too large. ```R (expect_error(my_function(.Machine$double.xmax))) ``` -------------------------------- ### vec_as_short_length() Error: NA Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() does not accept NA values. This example shows the error for NA input. ```R (expect_error(my_function(NA))) ``` -------------------------------- ### Benchmarking vec_order() vs base_order() with Varying String Sizes Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Investigates the effect of string size on the performance of `vec_order()` and `base_order()`. The benchmark uses a large number of groups and varying string sizes to assess performance. ```r set.seed(123) size <- 1e6 n_groups <- 10 ^ (1:6) string_size <- c(10, 20, 40, 60, 80, 100) df <- bench::press( string_size = string_size, n_groups = n_groups, { dict <- new_dictionary(n_groups, string_size, string_size) x <- sample(dict, size, replace = TRUE) bench::mark(vec_order(x), base_order(x), iterations = 10) } ) ``` -------------------------------- ### vec_as_short_length() Error: Fractional Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() requires a whole number. This example shows the error when a fractional number is provided. ```R (expect_error(my_function(1.5))) ``` -------------------------------- ### Vector Size Operations in vctrs Source: https://github.com/r-lib/vctrs/blob/main/README.md Demonstrates common vector size operations like finding the common size and recycling vectors. Requires loading the vctrs library. ```r library(vctrs) # Sizes vec_size_common(1, 1:10) #> [1] 10 str(vec_recycle_common(1, 1:10)) #> List of 2 #> $ : num [1:10] 1 1 1 1 1 1 1 1 1 1 #> $ : int [1:10] 1 2 3 4 5 6 7 8 9 10 ``` -------------------------------- ### vec_as_short_length() Error: Vector Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() expects a single number, not a vector. This example demonstrates the error for vector inputs. ```R (expect_error(my_function(1:2))) ``` -------------------------------- ### Validate `which` argument length in vec_detect_run_bounds Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/runs.md Checks that the `which` argument in `vec_detect_run_bounds()` has a valid length, either 1 or a permutation of 'start' and 'end'. ```R vec_detect_run_bounds(1, which = c("foo", "bar")) ``` -------------------------------- ### Benchmarking vec_order() vs base_order() with Large Random Strings Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Compares `vec_order()` and `base_order()` on a very large set of random strings. `vec_order()` shows slightly higher memory usage but comparable execution time. ```r set.seed(123) n_groups <- 1e7 x <- new_dictionary(n_groups, min_length = 5, max_length = 20) bench::mark(vec_order(x), base_order(x), iterations = 10) ``` -------------------------------- ### Validate `which` argument in vec_detect_run_bounds Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/runs.md Ensures that the `which` argument in `vec_detect_run_bounds()` is correctly validated to be either 'start' or 'end', preventing invalid inputs. ```R vec_detect_run_bounds(1, which = "x") ``` -------------------------------- ### Default Print Method for Vectors Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/type-vctr.md Illustrates the default print method for vectors, showing their content and structure. ```R h ``` ```R h[0] ``` ```R h ``` -------------------------------- ### Custom error message with vec_as_location() and environment input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/subscript-loc.md Demonstrates how to provide custom argument names and call stack information when vec_as_location() encounters an invalid environment input. This helps in debugging by specifying the context of the error. ```r (expect_error(vec_as_location(env(), 10L, arg = "foo", call = call( "my_function")), class = "vctrs_error_subscript_type")) ``` -------------------------------- ### Validate `which` argument length in vec_locate_run_bounds Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/runs.md Validates the length of the `which` argument in `vec_locate_run_bounds()`. It must be of length 1 or a permutation of 'start' and 'end'. ```R vec_locate_run_bounds(1, which = c("foo", "bar")) ``` -------------------------------- ### Abbreviate data.frame structure Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/ptype-abbr-full.md Use `vec_ptype_abbr()` to get a concise abbreviation of a data.frame's structure, including custom constructors. ```r df <- foobar(data.frame(x = 1, y = "", z = TRUE)) vec_ptype_abbr(df) ``` -------------------------------- ### vec_size_common() Error: Vector Size Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_size_common() expects a single number for its size argument. This example shows the error when a vector is provided. ```R (expect_error(vec_size_common(.size = 1:2))) ``` -------------------------------- ### vec_size_common() Error: String Size Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_size_common() expects a single number for its size argument. This example shows the error when a string is provided. ```R (expect_error(vec_size_common(.size = "foo"))) ``` -------------------------------- ### obj_check_list() with empty string arg Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md Demonstrates the special error raised by obj_check_list() when the 'arg' parameter is an empty string. ```R obj_check_list(1, arg = "") ``` -------------------------------- ### vec_check_list() Functionality Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/lifecycle-deprecated.md Demonstrates the expected behavior and error conditions for vec_check_list(). ```R vec_check_list(1) ``` ```R my_check(1) ``` -------------------------------- ### Validate sizes argument non-negativity in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The `sizes` argument cannot contain negative values. This example demonstrates an error for a negative size. ```R vec_chop("a", sizes = -1) ``` -------------------------------- ### Get full data.frame structure Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/ptype-abbr-full.md Use `vec_ptype_full()` to obtain a detailed, human-readable representation of a data.frame's structure and column types. ```r vec_ptype_full(df) ``` -------------------------------- ### Error: `n` can't be negative or missing Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/type-data-frame.md The `n` argument for `new_data_frame()` cannot be negative or NA. These examples show the corresponding error messages. ```R (expect_error(new_data_frame(n = -1L))) ``` ```R (expect_error(new_data_frame(n = NA_integer_))) ``` -------------------------------- ### Informative errors for `no_match` Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/match.md Demonstrates how `vec_locate_matches()` provides specific error messages when `no_match` is set to 'error' and no matches are found. It also shows how argument names can be customized in error messages. ```R (expect_error(vec_locate_matches(1, 2, no_match = "error"))) ``` ```R (expect_error(vec_locate_matches(1, 2, no_match = "error", needles_arg = "foo") )) ``` ```R (expect_error(vec_locate_matches(1, 2, no_match = "error", needles_arg = "foo", error_call = call("fn")))) ``` ```R (expect_error(vec_locate_matches(1, 2, no_match = "error", needles_arg = "foo", haystack_arg = "bar"))) ``` -------------------------------- ### Check recyclability with NULL elements using list_check_all_recyclable Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md This demonstrates `list_check_all_recyclable()` where `allow_null = TRUE` is used. It shows an error when an element's size cannot be recycled to the target size, even when NULLs are permitted. ```r list_check_all_recyclable(x, size = 2) ``` ```r list_check_all_recyclable(x, size = 2, allow_null = TRUE) ``` -------------------------------- ### vec_size_common() Error: Absent Argument Missing Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_size_common() requires the `.absent` argument when `...` is empty. This example demonstrates the error when `.absent` is not provided. ```R (expect_error(vec_size_common(.absent = NULL))) ``` -------------------------------- ### vec_size_common() Error: Incompatible Size Recycling Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_size_common() errors when arguments have incompatible sizes that cannot be recycled. This example shows the error when recycling fails. ```R (expect_error(my_function(this_arg = 1:2, that_arg = int()))) ``` -------------------------------- ### Benchmarking vec_order() vs base_order() on Nearly Sorted Integer Sequences Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Compares `vec_order()` and `base_order()` on a nearly sorted integer vector. Base R's `order()` shows a slight performance advantage, but the difference is not dramatic. ```r x <- c(1:1e7, 1:20) + 0L bench::mark( vec_order(x), base_order(x), iterations = 20 ) ``` -------------------------------- ### Benchmarking vec_order() vs base_order() on Sorted Integer Sequences Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Compares `vec_order()` and `base_order()` on a large, sorted integer vector. Base R's `order()` is faster due to a simpler check and ALTREP result, with minimal memory allocation. ```r x <- 1:1e7 + 0L # Base is faster (simpler check + ALTREP result) bench::mark( vec_order(x), base_order(x), iterations = 50 ) ``` ```r # But tweak some options and it becomes closer bench::mark( vec_order(x, direction = "desc", na_value = "smallest"), base_order(x, decreasing = TRUE, na.last = FALSE), iterations = 50 ) ``` -------------------------------- ### Disallow compact_seq indices in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The `vec_chop()` function does not support `compact_seq()` objects directly as indices. This example shows the internal error that occurs. ```R vec_chop(1:2, indices = list(compact_seq(1, 2))) ``` -------------------------------- ### Default str Method for Vectors Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/type-vctr.md Shows the default `str()` method for vectors, providing a compact representation of their structure. ```R str(h) ``` -------------------------------- ### vec_as_short_length() Error: Integer NA Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() does not accept integer NA values. This example shows the error for integer NA input. ```R (expect_error(my_function(na_int))) ``` -------------------------------- ### Disallow both indices and sizes in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The `vec_chop()` function does not allow both the `indices` and `sizes` arguments to be supplied simultaneously. This example shows the resulting error. ```R vec_chop(1, indices = list(1), sizes = 1) ``` -------------------------------- ### Benchmark: Multiple Character Columns Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Compares `vec_order()` and `base_order()` on a data frame with 20 character columns, each having only 2 groups. This tests performance with character data and many columns. ```r set.seed(123) size <- 1e6L n_groups <- 2 n_cols <- 20 cols <- replicate( n_cols, { dict <- new_dictionary(n_groups, 5, 10) sample(dict, size, TRUE) }, simplify = FALSE ) names(cols) <- seq_along(cols) df <- vctrs::new_data_frame(cols, size) bench::mark(vec_order(df), base_order(df), iterations = 10) #> # A tibble: 2 x 6 #> expression min median `itr/sec` mem_alloc `gc/sec` #> #> 1 vec_order(df) 368ms 373ms 2.67 32.54MB 0.668 #> 2 base_order(df) 278ms 292ms 3.43 3.82MB 0 ``` -------------------------------- ### Load Required Libraries Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Loads necessary R libraries for data manipulation, benchmarking, and plotting. ```r library(vctrs) library(rlang) library(stringr) library(ggplot2) library(dplyr) library(forcats) ``` -------------------------------- ### Validate sizes argument type in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The `sizes` argument must be convertible to integers. This example shows an error when a character vector is provided. ```R vec_chop("a", sizes = "a") ``` -------------------------------- ### list_check_all_vectors() with mixed list and environment Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md Illustrates errors from list_check_all_vectors() when a list contains an environment, which is not a vector. ```R (expect_error(my_function(list(1, env())))) ``` ```R (expect_error(my_function(list(1, name = env())))) ``` ```R (expect_error(my_function(list(1, foo = env())))) ``` -------------------------------- ### Validate indices argument in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The `indices` argument must be a list of index values or NULL. This example shows an error when a non-list is provided. ```R vec_chop(1, indices = 1) ``` -------------------------------- ### vec_as_short_length() Error: Negative or Zero Input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/size.md vec_as_short_length() requires a positive number or zero. This example shows the error when a negative number is provided. ```R (expect_error(my_function(-1))) ``` -------------------------------- ### Benchmark vec_order vs vec_unique_loc for integers (small size) Source: https://github.com/r-lib/vctrs/blob/main/bench/sorting-vs-hashing.md Benchmarks vec_order() and vec_unique_loc() for integer vectors with varying total sizes (up to 10000) and group sizes. Uses 100 iterations per test. ```r set.seed(123) size <- 10 ^ (1:4) n_groups <- 10 ^ (1:6) df <- bench::press( size = size, n_groups = n_groups, { x <- sample(n_groups, size, replace = TRUE) bench::mark( vec_order(x), vec_unique_loc(x), iterations = 100, check = FALSE ) } ) ``` -------------------------------- ### obj_check_list() errors on environments Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md obj_check_list() validates that its input is a list. This example shows how it errors when an environment is passed to a function that uses obj_check_list internally. ```R my_function <- (function(my_arg) obj_check_list(my_arg)) (expect_error(my_function(env()))) ``` -------------------------------- ### Error context for incompatible sizes in df_list() Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/type-data-frame.md Demonstrates error reporting for incompatible vector sizes when creating a list of data frames with `df_list()`, including custom error call context. ```R (expect_error(df_list(a = 1:2, b = int()))) ``` ```R (expect_error(df_list(a = 1:2, b = int(), .error_call = call("foo")))) ``` -------------------------------- ### Validate `which` argument in vec_locate_run_bounds Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/runs.md Validates the `which` argument in `vec_locate_run_bounds()` to ensure it is either 'start' or 'end'. Incorrect values will result in an informative error message. ```R vec_locate_run_bounds(1, which = "x") ``` -------------------------------- ### list_of() Source: https://context7.com/r-lib/vctrs/llms.txt Creates a typed list with constraints on element type and size. Elements are automatically coerced and recycled upon assignment. ```APIDOC ## `list_of()` — Typed list with constraints on element type and size A restricted list where all elements must share the same type (`.ptype`) and/or size (`.size`). Assignment coerces and recycles automatically. ```r library(vctrs) # Restrict element type to integer x <- list_of(1:3, 5:6, 10:15) x #> [3]> #> [[1]] [1] 1 2 3 #> [[2]] [1] 5 6 #> [[3]] [1] 10 11 12 13 14 15 # Assignment coerces to integer x[1] <- list(4) # 4 -> 4L typeof(x[[1]]) #> "integer" try(x[1] <- list(4.5)) # Error: can't cast double with fraction to integer # Restrict to size 2 (any type) y <- list_of(1, 2:3, .ptype = rlang::zap(), .size = 2) y[1] <- list(4) # recycled: list(c(4, 4)) # Both type and size constraints z <- list_of(1L, 2:3, .ptype = integer(), .size = 2) # Introspect constraints list_of_ptype(z) #> integer(0) list_of_size(z) #> [1] 2 # Combining list_of with list gives plain list vec_c(list_of(1), list(2, "x")) #> [[1]] 1 [[2]] 2 [[3]] "x" ``` ``` -------------------------------- ### Check for invalid '..j' names with validate_unique() Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/names.md validate_unique() prevents names that start with '..' followed by numbers, as these are reserved for internal use. ```R (expect_error(validate_unique(chr("..1")), class = "vctrs_error_names_cannot_be_dot_dot") ) ``` -------------------------------- ### list_check_all_size() error on scalar input Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md Demonstrates list_check_all_size() errors when given a scalar input, expecting a list. ```R my_function <- (function(my_arg, size) list_check_all_size(my_arg, size)) (expect_error(my_function(x, 2))) ``` -------------------------------- ### Informative scalar type errors Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/conditions.md Shows how vctrs provides informative error messages for scalar type mismatches, guiding users on how to fix them. ```R expect_error(vec_slice(foobar(list(1)), 1), class = "vctrs_error_scalar_type") ``` ```R expect_error(stop_scalar_type(foobar(list(1)), arg = "foo"), class = "vctrs_error_scalar_type") ``` -------------------------------- ### list_check_all_size() with incorrect size Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/assert.md Demonstrates list_check_all_size() errors when elements in a list do not match the specified size. ```R (expect_error(list_check_all_size(list(1:2, 1:3), 2))) ``` ```R (expect_error(my_function(list(1:2, 1:3), 2))) ``` ```R (expect_error(my_function(list(NULL, 1:2), 2))) ``` -------------------------------- ### Profile vec_rbind() performance Source: https://github.com/r-lib/vctrs/blob/main/bench/rbind.md Uses `profvis::profvis()` to profile the performance of `vec_rbind()` to identify bottlenecks. Further improvements may require a C rewrite. ```r profvis::profvis(vec_rbind(!!!dfs)) ``` -------------------------------- ### Validate sizes argument for missing values in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The `sizes` argument cannot contain missing values (NA). This example shows an error when NA is present. ```R vec_chop("a", sizes = NA_integer_) ``` -------------------------------- ### Benchmarking vec_order() vs base_order() on Nearly Sorted Double Sequences Source: https://github.com/r-lib/vctrs/blob/main/bench/order.md Compares `vec_order()` and `base_order()` on a nearly sorted double vector. The performance difference observed with integers largely disappears with double-precision floating-point numbers. ```r x <- c(1:1e7, 1:20) + 0 bench::mark( vec_order(x), base_order(x), iterations = 20 ) ``` -------------------------------- ### Validate index bounds in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md The indices provided in the `indices` list must be within the bounds of the input vector. This example shows an out-of-bounds error. ```R (expect_error(vec_chop(1, indices = list(2)), class = "vctrs_error_subscript_oob") ) ``` -------------------------------- ### Validate index type in vec_chop Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/slice-chop.md When `indices` is a list, its elements must be convertible to integers. This example demonstrates an error when a double with loss of precision is used. ```R (expect_error(vec_chop(1, indices = list(1.5)), class = "vctrs_error_subscript_type") ) ``` -------------------------------- ### vec_cbind() duplicate name de-duplication Source: https://github.com/r-lib/vctrs/blob/main/tests/testthat/_snaps/bind.md When duplicate names are provided to vec_cbind(), they are automatically de-duplicated by appending suffixes. This example shows the resulting names and output. ```R (expect_named(vec_cbind(x = 1, x = 1), c("x...1", "x...2"))) ``` ```R (expect_named(vec_cbind(data.frame(x = 1), data.frame(x = 1)), c("x...1", "x...2"))) ```