
Creates a Nix expression that reads in a file (or folder of data) using R.
Source:R/rxp_io.R
rxp_r_file.RdCreates a Nix expression that reads in a file (or folder of data) using R.
Arguments
- ...
Arguments passed on to
rxp_filenameSymbol, the name of the derivation.
pathCharacter, the file path to include (e.g., "data/mtcars.shp") or a folder path (e.g., "data"). See details.
read_functionFunction, an R function to read the data, taking one argument (the path). This can be a user-defined function that is made available using
user_functions. See details.user_functionsCharacter vector, user-defined functions to include. This should be a script (or scripts) containing user-defined functions to include during the build process for this derivation. It is recommended to use one script per function, and only include the required script(s) in the derivation.
nix_envCharacter, path to the Nix environment file, default is "default.nix".
env_varList, defaults to NULL. A named list of environment variables to set before running the R script, e.g., c(VAR = "hello"). Each entry will be added as an export statement in the build phase.
encoderFunction/character, defaults to NULL. A language-specific serializer to write the loaded object to disk.
R: function/symbol/character (e.g.,
qs::qsave) taking(object, path). Defaults tosaveRDS.Python: character name of a function taking
(object, path). Defaults to usingpickle.dump.Julia: character name of a function taking
(object, path). Defaults to usingSerialization.serialize.
Details
The basic usage is to provide a path to a file, and the function
to read it. For example: rxp_r_file(mtcars, path = "data/mtcars.csv", read_function = read.csv).
It is also possible instead to point to a folder that contains many
files that should all be read at once, for example:
rxp_r_file(many_csvs, path = "data", read_function = \(x)(readr::read_csv(list.files(x, full.names = TRUE, pattern = ".csv$")))).
See the vignette("importing-data") vignette for more detailed examples.
See also
Other derivations:
rxp_jl(),
rxp_jl_file(),
rxp_py(),
rxp_py_file(),
rxp_qmd(),
rxp_r(),
rxp_rmd()