This tutorial demonstrates the basics of session management.
library(dsBaseClient)
ds.ls()
## $server1
## $server1$environment.searched
## [1] "R_GlobalEnv"
##
## $server1$objects.found
## [1] "cnsim" "dasim" "survival" "titanic"
##
##
## $server2
## $server2$environment.searched
## [1] "R_GlobalEnv"
##
## $server2$objects.found
## [1] "cnsim" "dasim" "survival" "titanic"
After you have been working on one or more data sources (e.g., manipulating data), you can save the manipulations on the server.
For example, suppose you have created an extra variable called data
:
ds.assign("cnsim", newobj = "a_new_object_i_made")
ds.ls()
## $server1
## $server1$environment.searched
## [1] "R_GlobalEnv"
##
## $server1$objects.found
## [1] "a_new_object_i_made" "cnsim" "dasim"
## [4] "survival" "titanic"
##
##
## $server2
## $server2$environment.searched
## [1] "R_GlobalEnv"
##
## $server2$objects.found
## [1] "a_new_object_i_made" "cnsim" "dasim"
## [4] "survival" "titanic"
You can save the remote workspace on each server so that next time you start you do not need to recreate this object.
datashield.workspace_save(conns, "my_remote_workspace")
Now log out from DataSHIELD:
datashield.logout(conns)
Now login again, but this time specify that you want to restore the previous workspace:
conns <- datashield.login(logins = logindata, restore = "my_remote_workspace")
Now we can check and see that the object we previously created still exists:
ds.ls()
## $server1
## $server1$environment.searched
## [1] "R_GlobalEnv"
##
## $server1$objects.found
## [1] "a_new_object_i_made" "cnsim" "dasim"
## [4] "survival" "titanic"
##
##
## $server2
## $server2$environment.searched
## [1] "R_GlobalEnv"
##
## $server2$objects.found
## [1] "a_new_object_i_made" "cnsim" "dasim"
## [4] "survival" "titanic"
This is not specific to DataSHIELD, but it is helpful to see how the two interact. Imagine you have performed a DataSHIELD operation which returns some summary information, e.g., a mean:
my_mean <- ds.mean("cnsim$LAB_TSC")
We can now save our local workspace in the current working directory using:
save.image("my_local_workspace")
To demonstrate that this has saved, clear the workspace:
rm(list = ls())
ls()
## character(0)
You’ll see the workspace is now empty. We can restore the saved workspace:
load("my_local_workspace")
ls()
## [1] "armadillo_url" "builder" "conns" "logindata" "my_mean"
## [6] "token"
Notice that the object my_mean
is now there again. Saving your local workspace alongside your remote workspace is good practice, saving time and avoiding rerunning analyses.
First we need to log in again.
You can check which remote tables you have access to with:
datashield.tables(conns)
## $server1
## [1] "ds-workshop-24/data/cnsim2" "ds-workshop-24/data/cnsim3"
## [3] "ds-workshop-24/data/cnsim1" "example-datasets/data/cnsim_1"
## [5] "example-datasets/data/depression_2" "example-datasets/data/dasim_2"
## [7] "example-datasets/data/cnsim_2" "example-datasets/data/survival_1"
## [9] "example-datasets/data/dasim_3" "example-datasets/data/cnsim_3"
## [11] "example-datasets/data/titanic_1" "example-datasets/data/titanic_2"
## [13] "example-datasets/data/survival_3" "example-datasets/data/depression_1"
## [15] "example-datasets/data/dasim_1" "example-datasets/data/survival_2"
##
## $server2
## [1] "CNSIM.CNSIM1"
## [2] "CNSIM.CNSIM2"
## [3] "CNSIM.CNSIM3"
## [4] "DASIM.DASIM1"
## [5] "DASIM.DASIM2"
## [6] "DASIM.DASIM3"
## [7] "DISCORDANT.DISCORDANT_STUDY1"
## [8] "DISCORDANT.DISCORDANT_STUDY2"
## [9] "DISCORDANT.DISCORDANT_STUDY3"
## [10] "GREENSPACE.Cohort1_exposome"
## [11] "GREENSPACE.Cohort2_exposome"
## [12] "GREENSPACE.Cohort3_exposome"
## [13] "MEDIATION.UPBdata1"
## [14] "MEDIATION.UPBdata2"
## [15] "MEDIATION.UPBdata3"
## [16] "SURVIVAL.EXPAND_WITH_MISSING1"
## [17] "SURVIVAL.EXPAND_WITH_MISSING2"
## [18] "SURVIVAL.EXPAND_WITH_MISSING3"
## [19] "TESTING.TESTING1"
## [20] "TESTING.TESTING2"
## [21] "TESTING.TESTING3"
## [22] "TITANIC_NEWCOMERS_WORKSHOP.titanic_server_1"
## [23] "TITANIC_NEWCOMERS_WORKSHOP.titanic_server_2"
## [24] "depression.growth_1"
## [25] "depression.growth_2"
## [26] "serverDataKey.myKey"
To check what remote packages are installed on each server:
datashield.pkg_status(conns)
## $package_status
## server1 server2
## dsBase TRUE TRUE
## base TRUE FALSE
## stats TRUE FALSE
## dsExposome TRUE TRUE
## dsMediation TRUE TRUE
## dsOmics TRUE TRUE
## dsSurvival TRUE TRUE
## dsTidyverse TRUE TRUE
## resourcer TRUE TRUE
## dsMTLBase FALSE TRUE
##
## $version_status
## server1 server2
## dsBase "6.3.1" "6.3.1"
## base NA NA
## stats NA NA
## dsExposome "2.0.9" "2.0.9"
## dsMediation "0.0.3" "0.0.3"
## dsOmics "1.0.18-2" "1.0.18-2"
## dsSurvival "2.1.3" "2.1.3"
## dsTidyverse "1.0.3" "1.0.3"
## resourcer "1.4.0" "1.4.0"
## dsMTLBase NA "0.9.9"
Profiles are collections of server-side packages. For more information on profiles, you can read here.
To check which profiles are installed:
datashield.profiles(conns)
## $available
## server1 server2
## default TRUE TRUE
## donkey TRUE FALSE
## xenon TRUE FALSE
## exposome FALSE TRUE
## geo FALSE TRUE
## lemon-donkey FALSE TRUE
## mediation FALSE TRUE
## mtl FALSE TRUE
## omics FALSE TRUE
## omop FALSE TRUE
## survival FALSE TRUE
##
## $current
## profile
## server1 donkey
## server2 lemon-donkey