Skip to main content
Topic: Change File Paths of an xcmsSet object (Read 5325 times) previous topic - next topic

Change File Paths of an xcmsSet object

Problem: You have changed your files from the original folder where you picked your data. ie xcmsSet is looking to the wrong directory
Answer: You can change the 'filepaths' in the xcmsSet object to point to the new location.
Prerequisites: some knowledge of grep is useful
How: Using the faahKO set we will change the filepaths to the home directory.

Code: [Select]
library(xcms)
library(faahKO)
cdfpath <- system.file("cdf", package = "faahKO")
cdffiles <- list.files(cdfpath, recursive = TRUE, full.names = TRUE)
xset <- xcmsSet(cdffiles) ## peak pick the data

xset@filepaths ## where the file information is stored.
The output is something like this:
 [1] "/Library/Frameworks/R.framework/Resources/library/faahKO/cdf/KO/ko15.CDF"
 ......
[12] "/Library/Frameworks/R.framework/Resources/library/faahKO/cdf/WT/wt22.CDF"

Now we need to uses these file paths and remove the stuff we don't want
Code: [Select]
files<-sub("/Library/Frameworks/R.framework/Resources/library/faahKO/cdf/" ,"", xset@filepaths)
##to change the file for a local setup
files ## look at the files for a local directory this will be based on your R dir ie getwd()
 [1] "KO/ko15.CDF" "KO/ko16.CDF" "KO/ko18.CDF" "KO/ko19.CDF" "KO/ko21.CDF" "KO/ko22.CDF" "WT/wt15.CDF" "WT/wt16.CDF" "WT/wt18.CDF"
[10] "WT/wt19.CDF" "WT/wt21.CDF" "WT/wt22.CDF"
The above code will allow you to change the files so that they are local to whatever your R directory is.

We can even make the file paths absolute again by removing and adding paths that we want.
Code: [Select]
files<-sub("/Library/Frameworks/R.framework/Resources/library/faahKO/cdf/" ,"~/Desktop/", xset@filepaths)
##if you want to change the absolute directory of the filepaths
## be careful on windose machines where the c:/ is needed and the tile is not used '~'

files ## have a look at the files
 [1] "~/Desktop/KO/ko15.CDF" "~/Desktop/KO/ko16.CDF" "~/Desktop/KO/ko18.CDF" "~/Desktop/KO/ko19.CDF" "~/Desktop/KO/ko21.CDF"
 [6] "~/Desktop/KO/ko22.CDF" "~/Desktop/WT/wt15.CDF" "~/Desktop/WT/wt16.CDF" "~/Desktop/WT/wt18.CDF" "~/Desktop/WT/wt19.CDF"
[11] "~/Desktop/WT/wt21.CDF" "~/Desktop/WT/wt22.CDF"
~~
H. Paul Benton
Scripps Research Institute
If you have an error with XCMS Online please send me the JOBID and submit an error via the XCMS Online contact page