I have > 2000 motif files (in meme format) which I have imported into R and converted each into PFMatrix objects. Next, I want to store each of these PFMatrix objects into a PFMatrixList object using a "for loop".
My first thoughts were to store each PFMatrix object into a base list() object as I imported them into R as such:
# move to directory of motif files
fl <- list.files()
# create an empty list
empty.list <- list()
for (i in 1:length(fl)) {
# load in meme file
meme <- read.delim(fl[i], ...)
# create a pfmatrix
pfm.matrix <- PFMatrix(ID = ...)
# add PFMatrix object to list
empty.list <- c(empty.list, pfm.matrix)
}
Instead of a base list() object I would prefer to add these PFMatrix objects to a PFMatrixList object in a similar manner, however, when I try to add a PFMatrix object to an already existing/or empty PFMatrixList object with the PFMatrixList()
function, I get the error:
Error in .local(x, use.names, ...) :
PFMatrixList() only accepts PFMatrix objects!
Is there a way to append PFMatrix objects to an already existing PFMatrixList object?