The lib_export
function exports a data library to
another library with a different directory and file format. The
function accepts a library to export, the new library name,
a destination path, and an engine name.
If the destination
path does not exist, the function will attempt to create it.
Note that the export will result in the current data in memory written to the new destination directory. If the library is loaded into the workspace, the workspace version will be considered the most current version, and that is the version that will be exported.
lib_export(x, nm, directory_path, engine, filter = NULL, standard_eval = FALSE)
The library to export.
The variable name to hold the new library.
The parameter will assume non-standard
(unquoted) evaluation unless the standard_eval
parameter is set
to TRUE.
The path to export the library to.
The name of the engine to use for the exported data. The engine name corresponds to the standard file extension of the data file type. Valid values are 'rds', 'Rdata', 'rda', 'sas7bdat', 'xpt', 'xls', 'xlsx', 'dbf', 'csv', and 'parquet'.
A filter string to limit which datasets are exported. The filter parameter accepts wildcards.
A TRUE or FALSE value which indicates whether to
use standard (quoted) or non-standard (unquoted) evaluation on the
nm
parameter. Default is FALSE. Use this parameter if you want to
pass the target library name in a variable.
The newly exported library.
Other lib:
is.lib()
,
lib_add()
,
lib_copy()
,
lib_delete()
,
lib_info()
,
lib_load()
,
lib_path()
,
lib_remove()
,
lib_replace()
,
lib_size()
,
lib_sync()
,
lib_unload()
,
lib_write()
,
libname()
,
print.lib()
# Create temp directory
tmp <- tempdir()
# Create library
libname(dat1, tmp)
# Add dat to library
lib_add(dat1, mtcars, iris)
# Export dat1 to dat2
lib_export(dat1, dat2, file.path(tmp, "export"), "rdata")
# library 'dat2': 2 items
# - attributes: rdata not loaded
# - path: C:\Users\User\AppData\Local\Temp\Rtmp0Sq3kt/export
# - items:
# Name Extension Rows Cols Size LastModified
# 1 mtcars rdata 32 11 8.1 Kb 2022-06-23 00:10:52
# 2 iris rdata 150 5 8.1 Kb 2022-06-23 00:10:52
# Clean up
lib_delete(dat1)
lib_delete(dat2)