Downloading Datasets with getDataset

opts_chunk$set(echo = TRUE)
# This chunk is only useful for BioConductor checks and shouldn't affect any other setup
if (!any(file.exists("~/.netrc", "~/_netrc"))) {
    labkey.netrc.file <- ImmuneSpaceR:::.get_env_netrc()
    labkey.url.base <- ImmuneSpaceR:::.get_env_url()

This vignette shows detailed examples for all functionalities of the getDataset method.

Create connections

As explained into the introductory vignette, datasets must be downloaded from ImmuneSpaceConnection objects. We must first instantiate a connection to the study or studies of interest. Throughout this vignette, we will use two connections, one to a single study, and one to to all available data.

sdy269 <- CreateConnection("SDY269")
all <- CreateConnection("")

List the datasets

Now that the connections have been instantiated, we can start downloading from themm but we need to figure out which datasets are available within our chosen studies. Printing the connections will, among other information, list the datasets availables. The listDatasets method will display only the information we are looking for.


Naturally, all contains every dataset available on ImmuneSpace as it combines all available studies. Additionaly, when creating connection object with verbose = TRUE, a call to the getDataset method with an invalid dataset name will return the list of valid datasets.


Calling getDataset returns a selected dataset as it is displayed on ImmuneSpace.

hai_269 <- sdy269$getDataset("hai")
hai_all <- all$getDataset("hai")


Because some datasets such as flow cytometry results can contain a large number of rows, the method returns data.table objects to improve performance. This is especially important with multi-study connections.


The datasets can be filtered before download. Filters should be created using Rlabkey's makeFilter function.

Each filter is composed of three part: A column name or column label An operator * A value or array of values separated by a semi-colon


# Get participants under age of 30
young_filter <- makeFilter(c("age_reported", "LESS_THAN", 30))

# Get a specific list of two participants
pid_filter <- makeFilter(c("participantid", "IN", "SUB112841.269;SUB112834.269"))

For a list of available operators, see ?Rlabkey::makeFilter.

# HAI data for participants of study SDY269 under age of 30
hai_young <- sdy269$getDataset("hai", colFilter = young_filter)

# List of participants under age 30
demo_young <- all$getDataset("demographics", colFilter = young_filter)

# ELISPOT assay results for two participants
mbaa_pid2 <- all$getDataset("elispot", colFilter = pid_filter)

Note that filtering is done before download. When performance is a concern, it is faster to do the filtering via the colfFilter argument than on the returned table.


Any dataset grid on ImmuneSpace offers the possibility to switch views between 'Default' and 'Full'. The Default view contains information that is directly relevant to the user. Sample description and results are joined with basic demographic. However, this is not the way data is organized in the database. The 'Full' view is a representation of the data as it is stored on ImmPort. The accession columns are used under the hood for join operations. They will be useful to developers and user writing reports to be displayed in ImmuneSpace studies.


Screen capture of the button bar of a dataset grid on ImmuneSpace.

The original_view argument decides which view is downloaded. If set to TRUE, the 'Full' view is returned.

full_hai <- sdy269$getDataset("hai", original_view = TRUE)


For additional information, refer to the 'Working with tabular data' video tutorial.


As explained in the introductory guide, the ImmuneSpaceConnection class is a R6 class. It means its objects have fields accessed by reference. As a consequence, they can be modified without making a copy of the entire object. ImmuneSpaceR uses this feature to store downloaded datasets and expression matrices. Subsequent calls to getDataset with the same input will be faster.

See ?R6::R6Class for more information about R6 class system.

We can see the data currently cached using the cache field. This is not intended to be used for data manipulation and only displayed here to explain what gets cached.

pcr <- sdy269$getDataset("pcr")

Different views are saved separately.

pcr_ori <- sdy269$getDataset("pcr", original_view = TRUE)

Because of the infinite number of filters and combinations of filters, we do not cache filtered datasets.

If, for any reason, a specific dataset needs to be redownloaded, the reload argument will clear the cache for that specific getDataset call and download the table again.

hai_269 <- sdy269$getDataset("hai", reload = TRUE)

Finally, it is possible to clear every cached dataset (and expression matrix).


Again, the cache field should never be modified manually. When in doubt, simply reload the dataset.

Session info


Try the ImmuneSpaceR package in your browser

Any scripts or data that you put into this service are public.

ImmuneSpaceR documentation built on Dec. 21, 2020, 2:01 a.m.