| Title: | Manage Collections of Datasets and Objects |
|---|---|
| Description: | Create, store, read and manage structured collections of datasets and other objects using a 'workspace', then bundle it into a compressed archive. Using open and interoperable formats makes it possible to exchange bundled data from 'R' to other languages such as 'Python' or 'Julia'. Multiple formats are supported 'Parquet', 'JSON', 'yaml', spatial data and raster data are supported. |
| Authors: | Eli Daniels [aut, cre], David Gohel [aut], ArData [cph, fnd] |
| Maintainer: | Eli Daniels <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.6 |
| Built: | 2026-05-27 07:55:09 UTC |
| Source: | https://github.com/ardata-fr/workspace |
Delete a dataset stored in a workspace. This function removes the dataset file and updates the workspace's object descriptions.
delete_dataset(x, data_name)delete_dataset(x, data_name)
x |
The workspace object. |
data_name |
The name of the dataset to delete from the workspace. |
Returns the workspace object passed to x parameter. Called primarily for side effects.
workspace for package documentation
Other functions to write in a workspace:
store_dataset(),
store_json(),
store_raster(),
store_rds(),
store_yaml()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z <- delete_dataset(x = z, data_name = "iris_dataset") zlibrary(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z <- delete_dataset(x = z, data_name = "iris_dataset") z
List all objects stored in a workspace object and returns results as a tibble.
list_object_in_workspace(x)list_object_in_workspace(x)
x |
the workspace |
Tibble object containing the following columns:
file: file path to stored object relative to workspace directory
name: name given to object upon storing
subdir: subdirectory of file, such as 'datasets' or 'assets'.
type: file type such as 'dataset', 'geospatial', 'yaml', etc...
timestamp: timestamp of last modification
workspace for package documentation
Other functions to read in a workspace:
read_dataset_in_workspace(),
read_json_str_in_workspace(),
read_raster_in_workspace(),
read_rds_in_workspace(),
read_timestamp(),
read_yaml_in_workspace()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") list_object_in_workspace(z)library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") list_object_in_workspace(z)
Create a new workspace, i.e. an object made of an R environment and a directory where datasets will be stored as parquet files.
new_workspace(dir = tempfile(pattern = "ws"))new_workspace(dir = tempfile(pattern = "ws"))
dir |
directory used to store datasets, by default uses temporary directory. |
an empty workspace object.
workspace for package documentation
Other functions to manage workspaces:
pack_workspace(),
unpack_workspace(),
workspace_bind(),
workspace_copy()
z <- new_workspace() zz <- new_workspace() z
Pack a workspace into a compressed file.
pack_workspace(x, file)pack_workspace(x, file)
x |
workspace object to pack. |
file |
file path to new compressed file. |
path to created compressed file.
workspace for package documentation
Other functions to manage workspaces:
new_workspace(),
unpack_workspace(),
workspace_bind(),
workspace_copy()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) file <- tempfile(fileext = ".zip") pack_workspace(x = z, file = file)library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) file <- tempfile(fileext = ".zip") pack_workspace(x = z, file = file)
Read a table from a dataset stored as parquet file in a workspace.
read_dataset_in_workspace(x, name)read_dataset_in_workspace(x, name)
x |
the workspace |
name |
name of the dataset stored in the workspace |
A tibble if the dataset is stored as parquet, and a
sf object if it is stored as a geospatial dataset
(see store_dataset() for details).
workspace for package documentation
Other functions to read in a workspace:
list_object_in_workspace(),
read_json_str_in_workspace(),
read_raster_in_workspace(),
read_rds_in_workspace(),
read_timestamp(),
read_yaml_in_workspace()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") read_dataset_in_workspace(z, name = "mtcars")library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") read_dataset_in_workspace(z, name = "mtcars")
Read a JSON file a dataset stored as a text file in a workspace.
read_json_str_in_workspace(x, name, subdir = NULL)read_json_str_in_workspace(x, name, subdir = NULL)
x |
the workspace |
name |
name associated with the json file stored in the workspace |
subdir |
Optional subdirectory used for the asset to retrieve |
A character string containing the JSON string.
workspace for package documentation
Other functions to read in a workspace:
list_object_in_workspace(),
read_dataset_in_workspace(),
read_raster_in_workspace(),
read_rds_in_workspace(),
read_timestamp(),
read_yaml_in_workspace()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", name = "an_example", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) read_json_str_in_workspace(z, "an_example")library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", name = "an_example", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) read_json_str_in_workspace(z, "an_example")
Read a raster dataset stored as a TIFF file in a workspace.
read_raster_in_workspace(x, name)read_raster_in_workspace(x, name)
x |
the workspace object |
name |
name of the raster dataset stored in the workspace |
The splatRaster object that was stored in TIFF format.
workspace for package documentation
Other functions to read in a workspace:
list_object_in_workspace(),
read_dataset_in_workspace(),
read_json_str_in_workspace(),
read_rds_in_workspace(),
read_timestamp(),
read_yaml_in_workspace()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) # Create and store example raster (requires terra package) if (requireNamespace("terra", quietly = TRUE)) { r <- terra::rast(ncols=10, nrows=10, vals=1:100) z <- store_raster(x = z, dataset = r, name = "example_raster") retrieved_raster <- read_raster_in_workspace(z, name = "example_raster") retrieved_raster }library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) # Create and store example raster (requires terra package) if (requireNamespace("terra", quietly = TRUE)) { r <- terra::rast(ncols=10, nrows=10, vals=1:100) z <- store_raster(x = z, dataset = r, name = "example_raster") retrieved_raster <- read_raster_in_workspace(z, name = "example_raster") retrieved_raster }
Read an R Object from a dataset stored as a RDS file in a workspace.
read_rds_in_workspace(x, name, subdir = NULL)read_rds_in_workspace(x, name, subdir = NULL)
x |
the workspace |
name |
name of the object stored in the workspace |
subdir |
Optional subdirectory used for the asset to retrieve |
the R object that was stored as an Rds file.
workspace for package documentation
Other functions to read in a workspace:
list_object_in_workspace(),
read_dataset_in_workspace(),
read_json_str_in_workspace(),
read_raster_in_workspace(),
read_timestamp(),
read_yaml_in_workspace()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) read_rds_in_workspace(z, name = "obj")library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) read_rds_in_workspace(z, name = "obj")
Read a timestamp associated with an object in a workspace.
read_timestamp(x, name, type, subdir = NULL)read_timestamp(x, name, type, subdir = NULL)
x |
the workspace |
name |
name of the object stored in the workspace |
type |
content type |
subdir |
Optional subdirectory used for the asset to retrieve |
A character string corresponding to the timestamp (date last modified) of the stored object.
workspace for package documentation
Other functions to read in a workspace:
list_object_in_workspace(),
read_dataset_in_workspace(),
read_json_str_in_workspace(),
read_raster_in_workspace(),
read_rds_in_workspace(),
read_yaml_in_workspace()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) read_timestamp(z, name = "obj", type = "rds", subdir = "r-object")library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) read_timestamp(z, name = "obj", type = "rds", subdir = "r-object")
Read a YAML file stored as a list object in a workspace. Returns the YAML content as an R list object.
read_yaml_in_workspace(x, name, subdir = NULL)read_yaml_in_workspace(x, name, subdir = NULL)
x |
the workspace |
name |
name associated with the YAML file stored in the workspace |
subdir |
Optional subdirectory used for the asset to retrieve |
A list object as read from the stored YAML file.
workspace for package documentation
Other functions to read in a workspace:
list_object_in_workspace(),
read_dataset_in_workspace(),
read_json_str_in_workspace(),
read_raster_in_workspace(),
read_rds_in_workspace(),
read_timestamp()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) config_list <- list( database = list( host = "localhost", port = 5432 ), settings = list( debug = TRUE, max_connections = 100 ) ) z <- store_yaml( x = z, list = config_list, filename = "config.yaml", name = "app_config", timestamp = "2023-11-12 11:37:41", subdir = "configs" ) read_yaml_in_workspace(z, "app_config", subdir = "configs")library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) config_list <- list( database = list( host = "localhost", port = 5432 ), settings = list( debug = TRUE, max_connections = 100 ) ) z <- store_yaml( x = z, list = config_list, filename = "config.yaml", name = "app_config", timestamp = "2023-11-12 11:37:41", subdir = "configs" ) read_yaml_in_workspace(z, "app_config", subdir = "configs")
Remove an object stored in a workspace.
rm_object_in_workspace(x, name, type, subdir = NULL)rm_object_in_workspace(x, name, type, subdir = NULL)
x |
the workspace |
name |
name of the object stored in the workspace |
type |
content type |
subdir |
Optional subdirectory used for the asset to retrieve |
Returns the workspace object passed to x parameter. Called primarily for side effects.
workspace for package documentation
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) rm_object_in_workspace( x = z, name = "obj", type = "rds", subdir = "r-object" )library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) rm_object_in_workspace( x = z, name = "obj", type = "rds", subdir = "r-object" )
Store a dataset in an existing workspace. The file format used depends on the class of dataset.
data.frame is written as a Parquet using the arrow package.
sf is written as a geopackage file (.gpkg) using the sf package.
splatRaster is written as a TIFF file (.tiff) format using terra package.
store_dataset( x, dataset, name, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )store_dataset( x, dataset, name, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )
x |
the workspace object |
dataset |
the data.frame or sf to store in the workspace. |
name |
name associated with the data.frame, if a workspace file with this name exists
already it will be replaced. The name is translated to ascii using
|
timestamp |
A timestamp string to associate with the entry in the workspace. |
Returns the workspace object passed to x parameter. Called primarily for side effects.
To store raster data, ensure that terra is installed. To store geospatial vector
and polygon data, ensure that sf is installed.
Storing geospatial vector and polygon data will also create an accompanying
metadata yaml file in the assets/sf_metadata/{name}.yaml location,
containing metadata for when the file is read.
workspace for package documentation
Other functions to write in a workspace:
delete_dataset(),
store_json(),
store_raster(),
store_rds(),
store_yaml()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") zlibrary(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") z
Saves a JSON string as a file in an existing workspace.
This function allows users to save JSON strings into a specified workspace. The file is saved under the provided filename and can be organized within a specific subdirectory for better management.
store_json( x, json_str, filename, name = NULL, subdir, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )store_json( x, json_str, filename, name = NULL, subdir, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )
x |
The workspace object. |
json_str |
The JSON string to save in the workspace. |
filename |
The name of the file used to store the JSON string in the workspace. |
name |
name associated with the object, if a workspace file with this name exists already it will be replaced. |
subdir |
A subdirectory within the asset directory where the JSON file will be stored. |
timestamp |
A timestamp string to associate with the entry in the workspace. |
Returns the workspace object passed to x parameter. Called primarily for side effects.
workspace for package documentation
Other functions to write in a workspace:
delete_dataset(),
store_dataset(),
store_raster(),
store_rds(),
store_yaml()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) zlibrary(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z
Store a SpatRaster object as a TIFF file into an existing workspace.
store_raster( x, dataset, name, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )store_raster( x, dataset, name, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )
x |
the workspace object |
dataset |
the SpatRaster object to store in the workspace. |
name |
name associated with the SpatRaster, if a workspace file with this name exists already it will be replaced. |
timestamp |
A timestamp string to associate with the entry in the workspace. |
Returns the workspace object passed to x parameter. Called primarily for side effects.
workspace for package documentation
Other functions to write in a workspace:
delete_dataset(),
store_dataset(),
store_json(),
store_rds(),
store_yaml()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) # Create example raster (requires terra package) if (requireNamespace("terra", quietly = TRUE)) { r <- terra::rast(ncols=10, nrows=10, vals=1:100) z <- store_raster(x = z, dataset = r, name = "example_raster") z }library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) # Create example raster (requires terra package) if (requireNamespace("terra", quietly = TRUE)) { r <- terra::rast(ncols=10, nrows=10, vals=1:100) z <- store_raster(x = z, dataset = r, name = "example_raster") z }
Saves an R object as an RDS file in an existing workspace. This function allows users to save R objects in a workspace by serializing them as RDS files. The RDS file is saved under the specified filename and organized within a subdirectory for better structure. The timestamp parameter helps to keep track of when the file was stored.
store_rds( x, obj, filename, name = NULL, subdir, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )store_rds( x, obj, filename, name = NULL, subdir, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )
x |
The workspace object. |
obj |
The R object to save as an RDS file. |
filename |
The name of the file used to store the RDS file in the workspace. |
name |
name associated with the object, if a workspace file with this name exists already it will be replaced. |
subdir |
A subdirectory within the asset directory where the RDS file will be stored. |
timestamp |
A timestamp string to associate with the entry in the workspace. |
Returns the workspace object passed to x parameter. Called primarily for side effects.
workspace for package documentation
Other functions to write in a workspace:
delete_dataset(),
store_dataset(),
store_json(),
store_raster(),
store_yaml()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) zlibrary(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) z
Saves a list object as a YAML file in an existing workspace.
This function allows users to save R list objects as YAML files into a specified workspace. The file is saved under the provided filename and can be organized within a specific subdirectory for better management.
store_yaml( x, list, filename, name = NULL, subdir, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )store_yaml( x, list, filename, name = NULL, subdir, timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S") )
x |
The workspace object. |
list |
The R list object to save as YAML in the workspace. |
filename |
The name of the file used to store the YAML file in the workspace. |
name |
name associated with the object, if a workspace file with this name exists already it will be replaced. |
subdir |
A subdirectory within the asset directory where the YAML file will be stored. |
timestamp |
A timestamp string to associate with the entry in the workspace. |
Returns the workspace object passed to x parameter. Called primarily for side effects.
workspace for package documentation
Other functions to write in a workspace:
delete_dataset(),
store_dataset(),
store_json(),
store_raster(),
store_rds()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) config_list <- list( database = list( host = "localhost", port = 5432, name = "mydb" ), settings = list( debug = TRUE, max_connections = 100 ) ) z <- store_yaml( x = z, list = config_list, filename = "config.yaml", timestamp = "2023-11-12 11:37:41", subdir = "configs" ) zlibrary(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) config_list <- list( database = list( host = "localhost", port = 5432, name = "mydb" ), settings = list( debug = TRUE, max_connections = 100 ) ) z <- store_yaml( x = z, list = config_list, filename = "config.yaml", timestamp = "2023-11-12 11:37:41", subdir = "configs" ) z
Unpack a compressed file into a workspace object.
unpack_workspace(file)unpack_workspace(file)
file |
Packed workspace |
Object of class workspace.
workspace for package documentation
Other functions to manage workspaces:
new_workspace(),
pack_workspace(),
workspace_bind(),
workspace_copy()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) file <- tempfile(fileext = ".zip") pack_workspace(x = z, file = file) z <- unpack_workspace(file = file) zlibrary(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) file <- tempfile(fileext = ".zip") pack_workspace(x = z, file = file) z <- unpack_workspace(file = file) z
Create, store, read and manage structured collections of datasets and other objects using a 'workspace', then bundle it into a compressed archive. Using open and interoperable formats makes it possible to exchange bundled data from 'R' to other languages such as 'Python' or 'Julia'. Multiple formats are supported 'Parquet', 'JSON', 'yaml', spatial data and raster data are supported.
Examples of usage are:
Creating a collection of datasets and parameters to save in a zip file.
Importing and exporting datasets and settings into from a shiny app.
To get started with workspace, you will need to create an empty one with
new_workspace() or unpack an existing workspace zip file with
unpack_workspace(). These functions return a list with class workspace that
which you can interact with using the following functions.
To store data:
store_dataset() for data.frames, sf and splatRaster
store_json() for json strings
store_rds() for R objects
store_yaml for storing a list in YAML format
Each object stored in a workspace will have an associated name which can then be used to retrieve the data with the following functions:
For interactive use, print() the workspace to the console to show the directory
of the workspace and its contents
list_object_in_workspace() to list objects in a workspace
read_timestamp() to read a timestamp associated with an object of a
workspace. Each time an object is stored, the timestamp is recorded
read_dataset_in_workspace() to read a dataset in a workspace
read_raster_in_workspace() to read a raster file in a workspace
read_rds_in_workspace() to read an Rds file in a workspace
read_json_str_in_workspace() to read a JSON string in a workspace
read_yaml_in_workspace() to read a YAML file in a workspace
Stored objects can be removed with:
rm_object_in_workspace() for any object
delete_dataset() for datasets
A workspace an also be compressed into a zip file using pack_workspace()
and unzipped using unpack_workspace(), which allows for saving a workspace
to reuse later or share a zip file with someone else.
Workspaces can be cloned using workspace_copy() or merged together with
workspace_bind().
Tabular datasets, such as objects of class data.frame or tibble are stored
as Parquet files. Geosptial formats are supported using store_dataset()
for splatRaster objects from the terra package and sf objects from the
sf package.
A workspace object is a list with class workspace with 2 elements; a directory folder
and version number.
The former is where the files are stored and read from, and the latter,
contains a version number for the workspace structure in case new versions
are required in future. A workspace therefore represents a folder and its files.
Note, to ensure validity of workspaces, they should be created and modified with functions from this package, not manually.
Maintainer: Eli Daniels [email protected]
Authors:
David Gohel [email protected]
Other contributors:
ArData [copyright holder, funder]
Useful links:
Bind a workspace into another workspace.
workspace_bind(x, y, replace = FALSE)workspace_bind(x, y, replace = FALSE)
x |
the workspace where y elements will be copied |
y |
the workspace to add to |
replace |
scalar logical, set to TRUE if you want to overwrite existing elements. |
workspace object resulting from bind operation.
workspace for package documentation
Other functions to manage workspaces:
new_workspace(),
pack_workspace(),
unpack_workspace(),
workspace_copy()
library(workspace) x <- new_workspace() x <- store_dataset(x = x, dataset = iris, name = "iris_dataset") z <- new_workspace() z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) new_x <- workspace_bind(x, z) new_xlibrary(workspace) x <- new_workspace() x <- store_dataset(x = x, dataset = iris, name = "iris_dataset") z <- new_workspace() z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) new_x <- workspace_bind(x, z) new_x
Clone/Copy a workspace. This function is necessary as assignment would not change internal directory that is certainly defined in a temporary directory that will be removed when R session will be stopped.
workspace_copy(x)workspace_copy(x)
x |
the workspace to copy |
New workspace copy
workspace for package documentation
Other functions to manage workspaces:
new_workspace(),
pack_workspace(),
unpack_workspace(),
workspace_bind()
library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) new_z <- workspace_copy(z)library(workspace) dir_tmp <- tempfile(pattern = "ws") z <- new_workspace(dir = dir_tmp) z <- store_dataset(x = z, dataset = iris, name = "iris_dataset") z <- store_dataset(x = z, dataset = mtcars, name = "mtcars") json_str <- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,", "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",", "\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"", "}}") z <- store_json( x = z, json_str = json_str, filename = "example.json", timestamp = "2023-11-12 11:37:41", subdir = "blah" ) z <- store_rds( x = z, obj = mtcars, filename = "obj.rds", timestamp = "2023-11-12 11:37:41", subdir = "r-object" ) new_z <- workspace_copy(z)