workspace
gives you the tools to create, store, read and
manage structured collections of datasets and other objects using a
‘workspace’, then bundle it into a compressed archive (zip).
The package’s main goal is to provide a standardized solution for organizing and sharing data in applications that require workspace management. 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’, geospatial and raster data are supported.
This package is aimed at developers and analysts seeking to
standardize data management in multi-environment or cross-application
contexts. With workspace
, creating, manipulating, and
sharing organized archives becomes straightforward.
You can install from CRAN with:
install.packages("pak")
You can install the development version of workspace from GitHub with:
::install_github("ardata-fr/workspace")
remotes# or
# pak::pak("ardata-fr/workspace")
This is a basic example which shows you how to create a workspace:
library(workspace)
<- new_workspace()
z
# store datasets
<- store_dataset(x = z, dataset = iris, name = "iris_dataset")
z <- store_dataset(x = z, dataset = mtcars, name = "mtcars")
z
# store json
<- paste0("{\"first_name\": \"John\",\"last_name\": \"Smith\",\"is_alive\": true,",
json_str "\"age\": 27, \"address\": { \"street_address\": \"21 2nd Street\",",
"\"city\": \"New York\",\"state\": \"NY\",\"postal_code\": \"10021-3100\"",
"}}")
<- store_json(
z x = z,
name = "json-example",
json_str = json_str,
filename = "json-example.json",
timestamp = "2023-11-12 11:37:41",
subdir = "blah"
)
# pack workspace as a zip to share it
<- tempfile(fileext = ".zip")
workspace_zip_file pack_workspace(x = z, file = workspace_zip_file)
#> [1] "C:/Users/EliDaniels/AppData/Local/Temp/RtmpSW1Piq/file71d87d2c26ba.zip"
This is a basic example which shows you how to extract data from a workspace:
<- unpack_workspace(file = workspace_zip_file)
z list_object_in_workspace(z)
#> # A tibble: 3 × 5
#> file name subdir type timestamp
#> <chr> <chr> <chr> <chr> <chr>
#> 1 datasets/iris_dataset.parquet iris_dataset datasets dataset 2025-09-01 14:26:…
#> 2 datasets/mtcars.parquet mtcars datasets dataset 2025-09-01 14:26:…
#> 3 assets/blah/json-example.json json-example blah json 2023-11-12 11:37:…
<- read_dataset_in_workspace(z, name = "mtcars")
dataset print(head(dataset))
#> # A tibble: 6 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
#> 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
#> 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
# store json
<- read_json_str_in_workspace(z, name = "json-example", subdir = "blah")
json_str substr(json_str, 1, 20) |> print()
#> [1] "{\"first_name\": \"John"
workspace
can be useful for managing datasets in Shiny
apps. The example shows how to create, add datasets, pack and unpack a
workspace.
library(workspace)
library(shiny)
library(readr)
library(shinyWidgets)
# Define UI for application that draws a histogram
<- fluidPage(
ui $h4("Add datasets to workspace"),
tags::fileInput(
shinyinputId = "file",
label = "Upload dataset",
accept = c("csv")
),textInput(
inputId = "name",
label = "Dataset name"
),actionButton(
inputId = "new",
label = "Add to workspace",
accept = c("csv")
),$hr(),
tags$h4("Import/export workspace"),
tags::fileInput(
shinyinputId = "import",
label = "Import workspace",
accept = c("zip")
),downloadButton(
outputId = "downloadData",
label = "Export workspace"
),$hr(),
tags$h4("Display workspace"),
tagstableOutput("workspace"),
selectInput(
inputId = "selector",
label = "Display table preview",
choices = character()
),tableOutput("table")
)
<- function(input, output) {
server <- reactiveValues(
rv curr_dataset = NULL,
ws = workspace::new_workspace(),
summary = NULL
)
# Import csv file ----------
observe({
req(input$file)
$curr_dataset <- shinyWidgets::execute_safely({
rv::read_csv(input$file$datapath, show_col_types = FALSE)
readr
})updateTextInput(
inputId = "name",
value = tools::file_path_sans_ext(input$file$name)
)
})
# Add new data set to workspace
observeEvent(input$new, {
<- req(rv$curr_dataset)
dataset req(rv$ws)
$ws <- workspace::store_dataset(x = rv$ws, dataset = dataset, name = trimws(input$name))
rv$summary <- workspace::list_object_in_workspace(rv$ws)
rv
})
# Display workspace metadata --------------
$workspace <- renderTable({
outputreq(rv$summary)
$summary
rv
})
observe({
req(nrow(rv$summary) > 0)
updateSelectInput(
inputId = "selector",
choices = rv$summary$name
)
})
$table <- renderTable({
outputreq(input$selector)
::read_dataset_in_workspace(x = rv$ws, name = input$selector) |>
workspacehead()
})
# Export workspace ------------
$downloadData <- downloadHandler(
outputfilename = function() {
paste("workspace-", Sys.Date(), ".zip", sep = "")
},content = function(file) {
::pack_workspace(x = rv$ws, file = file)
workspace
}
)
# Import workspace ----------
observeEvent(input$import, {
$ws <- workspace::unpack_workspace(file = input$import$datapath)
rv$summary <- workspace::list_object_in_workspace(rv$ws)
rv
})
}
shinyApp(ui = ui, server = server)