# retrieve clinical data
clin_file <- system.file("cli/merge", "meta.csv",
package = "SomaDataIO",
mustWork = TRUE)
clin_file
# view clinical data to be merged:
# 1) `group`
# 2) `newvar`
clin_df <- read.csv(clin_file, colClasses = c(SampleId = "character"))
clin_df
# create mini-adat
apts <- withr::with_seed(123, sample(getAnalytes(example_data), 2L))
adat <- head(example_data, 9L) |> # 9 x 2
dplyr::select(SampleId, all_of(apts))
# merge clinical variables
merged <- merge_clin(adat, clin_df, by = "SampleId")
merged
# Alternative syntax:
# 1) pass file path
# 2) merge on different variable names
# 3) convert join type on-the-fly
clin_file2 <- system.file("cli/merge", "meta2.csv",
package = "SomaDataIO",
mustWork = TRUE)
id_type <- typeof(adat$SampleId)
merged2 <- merge_clin(adat, clin_file2, # file path
by = c(SampleId = "ClinKey"), # join on 2 variables
by_class = c(ClinKey = id_type)) # match types
merged2
Run the code above in your browser using DataLab