tsSample-class: Class for representing samples

tsSample-classR Documentation

Class for representing samples


This is a class to represent a set of samples.

Objects from the Class

Objects can be created by the function ImportSamples or by calling the object generator function.

new("tsSample", Names = [sample names], CDFfiles = [list of CDF file names], RIfiles = [list of RI file names], CDFpath = [CDF files path], RIpath = [RI files path], days = [measurement days], data = [additional sample information], ftype = [RI file format])



"character", the sample names.


"character", the list of CDF file names.


"character", the list of RI file names.


"character", CDF files path. Deprecated. See Notes.


"character", RI file path. Deprecated. See Notes.


"character", measurement days.


"data.frame", additional sample information.



signature(x = "tsSample"): Selects a subset of samples.


signature(x = "tsSample"): Access column name of sampleData slot.


signature(obj = "tsSample"): list of CDF files.


signature(obj = "tsSample"): list of RI files.


signature(obj = "tsSample"): The RI file path.


signature(obj = "tsSample"): The CDF file path.


signature(x = "tsSample"): number of samples.


signature(obj = "tsSample"): additional sample information.


signature(obj = "tsSample"): measurement days.


signature(obj = "tsSample"): sample names. The names must be unique


signature(object = "tsSample"): the show function.


signature(obj = "tsSample"): Sets or gets the RI file format. Options are either "binary" or "text". See note below.


Function to combine multiple objects.


The method fileFormat only changes the internal information of the file type and not the files themselves. To actually change the files, use the functions bin2text and text2bin.

Note that the slot Names (i.e., the sample names/identifiers) must be unique. This allows sample selection by using sample identifiers as well as indices. Also, if columns are selected, the output will be either a vector or a data.frame depending on whether one or more columns were selected. More over, it is required that the rownames of the data slot are equal to the sample names slots. This is handled internally. If the Names are not provided, then the CDF files are used instead (directories and extension are removed). In this case the file names must be unique.

The slots CDFpath and RIpath are deprecated and not used. However, the methods to set or get the paths will still work. The file paths is stored on the CDFfiles and RIfiles slots.

The c method requires that the combination of all objects have unique identifiers (names), or in other words, the objects cannot share identifiers. Duplicated identifiers are not allowed and an error will be thrown. This method also requires that the column names of the data slot (see method sampleData) are the same, because the method calls rbind internally.


Alvaro Cuadros-Inostroza, Matthew Hannah, Henning Redestig

See Also




# get a list of CDF files from a directory
CDFpath <- tsd_data_path()
cdffiles <- dir(CDFpath, "cdf", full=TRUE)

# define the RI file path
RIpath  <- "."

# create a tsSample object with minimal info
sampleDescription <- new("tsSample", CDFfiles = cdffiles, RIpath = RIpath)

## ## ## ## ##

# Alternatively, the CDF path and CDF file names can be given separately
# (this was the old TargetSearch behavior)
cdffiles <- basename(cdffiles)

# create the sample object
sampleDescription <- new("tsSample", CDFfiles = cdffiles, CDFpath = CDFpath, RIpath = RIpath)

## ## ## ## ##

# More parameters could be defined:
# define the RI files and the RI path
RIfiles <- sub("cdf$", "txt", paste("RI_", cdffiles, sep = ""))
RIpath  <- "."

# get the measurement days (the four first numbers of the cdf files, in this
# example)
days <- substring(cdffiles, 1, 4)

# sample names (must be unique)
smp_names <- paste("Sample", 1:length(sampleDescription), sep = "_")

# add some sample info
smp_data <- data.frame(CDF_FILE =cdffiles, GROUP = gl(5,3))

# create the sample object
sampleDescription <- new("tsSample", Names = smp_names, CDFfiles = cdffiles, CDFpath = CDFpath,
    RIpath = RIpath, days = days, RIfiles = RIfiles, data = smp_data)

# change the file paths (relative to the working path)
CDFpath(sampleDescription) <- "my_cdfs"
RIpath(sampleDescription)  <- "my_RIs"

# change sample Names
sampleNames(sampleDescription) <- sprintf("S%03d", 1:length(sampleDescription))

## sample subsetting.
# select samples 1, 3 and 5
(sampleset <- sampleDescription[c(1, 3, 5)])

# or use sample IDs
(sampleset <- sampleDescription[c("S001", "S003", "S005")])

## extract columns
# select column 'GROUP'
(group <- sampleDescription$GROUP)
# or
(group <- sampleDescription[, 'GROUP'])

## change the measurement days (sets the same day for all samples)
sampleDays(sampleDescription) <- "1"

## Note: the length of `measurement days` variable must be 1 or equal
## to the number of samples, otherwise an error will be thrown

## objects can be combined with the c() function
samp1 <- sampleDescription[1:5]
samp2 <- sampleDescription[6:10]
samp3 <- sampleDescription[11:15]
samp <- c(samp1, samp2, samp3)

acinostroza/TargetSearch documentation built on June 14, 2024, 8:03 a.m.