Data input class
PMData.RdRepresents a single input data file with its ID and path. This is a minimal representation that will be extended later with reading/writing capabilities.
Public fields
idCharacter. The canonical identifier for this input (e.g., "feature_table")
pathCharacter. The absolute path to the input file
Methods
Method read()
Read the data file
Arguments
...Additional arguments passed to
pm_read_file
Method exists()
Check if the data file exists
Examples
withr::with_tempdir({
data <- PMData$new(id = "feature_table", path = "file.csv")
data$exists() # FALSE - file doesn't exist yet
df <- data.frame(x = 1:5, y = letters[1:5])
data$write(df)
data$exists() # TRUE - file now exists
})Method write()
Write data to the file
Arguments
xThe object to write. For tabular formats (CSV, TSV, Parquet), must be a data.frame. For RData files, can accept multiple objects via
.......Additional arguments passed to
pm_write_file. For RData files, additional objects can be provided here.
Examples
withr::with_tempdir({
data <- PMData$new(id = "feature_table", path = "file.csv")
df <- data.frame(x = 1:5, y = letters[1:5])
data$write(df)
# For RData files, can write multiple objects
data_rdata <- PMData$new(id = "results", path = "results.RData")
obj1 <- data.frame(x = 1:3)
obj2 <- c("a", "b", "c")
data_rdata$write(obj1, obj2, obj3 = 42)
})Examples
data <- PMData$new(id = "feature_table", path = "/path/to/file.biom")
data$id
#> [1] "feature_table"
data$path
#> [1] "/path/to/file.biom"
## ------------------------------------------------
## Method `PMData$read`
## ------------------------------------------------
if (FALSE) { # \dontrun{
data <- PMData$new(id = "feature_table", path = "/path/to/file.csv")
contents <- data$read()
} # }
## ------------------------------------------------
## Method `PMData$exists`
## ------------------------------------------------
withr::with_tempdir({
data <- PMData$new(id = "feature_table", path = "file.csv")
data$exists() # FALSE - file doesn't exist yet
df <- data.frame(x = 1:5, y = letters[1:5])
data$write(df)
data$exists() # TRUE - file now exists
})
#> [1] TRUE
## ------------------------------------------------
## Method `PMData$write`
## ------------------------------------------------
withr::with_tempdir({
data <- PMData$new(id = "feature_table", path = "file.csv")
df <- data.frame(x = 1:5, y = letters[1:5])
data$write(df)
# For RData files, can write multiple objects
data_rdata <- PMData$new(id = "results", path = "results.RData")
obj1 <- data.frame(x = 1:3)
obj2 <- c("a", "b", "c")
data_rdata$write(obj1, obj2, obj3 = 42)
})