ahmohamed / lipidr

Data Mining and Analysis of Lipidomics datasets in R
https://www.lipidr.org/
Other
27 stars 13 forks source link

add_sample_annotation #49

Closed DavidGO464 closed 1 year ago

DavidGO464 commented 1 year ago

Just to make sure that whenever you add sample annotation you just DONO't use the name of the object in the environment. you need to use the name of the file. for instance:

d <- add_sample_annotation(d, anotation) - this will not work , you will have the error ( Error in .check_sample_annotation(data, annot) : All sample names must be in the first column or a column named "Sample")

on the other hand, d <- add_sample_annotation(d, "anotation.csv") - this will work

this is not explained in the documentation but it should

ahmohamed commented 1 year ago

As per the documentation here, annot_file can either be a file or a data.frame, so yes you CAN use objects in the environment if they are correctly formatted.

The code from the example below, but modified to read in the file first as a data.frame.

datadir <- system.file("extdata", package = "lipidr")

# all csv files
filelist <- list.files(datadir, "data.csv", full.names = TRUE)
d <- read_skyline(filelist)

# Add clinical info to existing LipidomicsExperiment object
clinical_file <- system.file("extdata", "clin.csv", package = "lipidr")

# Read the file as a data.frame
clin_df = read.csv(clinical_file)

# Pass the data.frame to add_sample_annotation
d <- add_sample_annotation(d, clin_df)

I suggest you closely inspect what is in your annot object and make sure it's the correct data.frame. If you still think the documentation is not clear, a PR is very welcome.

ahmohamed commented 1 year ago

Closing. Feel free to reopen if this is still an issue.