Closed otaviolovison closed 2 years ago
Hello Otávio!
Unfortunately, R
does not allow column names to start with numbers.
For example, if you'll try to load a data with read.table
, by default R
will add "X" before the number in column names.
As a workaround, you may rename the samples in phyloseq
object, convert to data.frame, and rename samples back:
sample_names(ps) <- paste0("z_", sample_names(ps))
psd <- phyloseq_to_df(ps)
colnames(psd) <- gsub(pattern = "^z_", replacement = "", x = colnames(psd))
With kind regards, Vladimir
It worked perfectly!
Thank you so much!
Hi @vmikk - Received same error message when trying to use the same function. Apparently, it is because there is special characters (hyphen) - in the sample ID (too many samples to change individually). Any work around that you might be able to suggest ?
Hello @tboonf! Have you tried the same trick with temporary sample renaming? E.g., you may replace a hyphen with double underscore (or something else that is not present in your sample names):
sample_names(ps) <- gsub(pattern = "-", replacement = "__", x = sample_names(ps))
psd <- phyloseq_to_df(ps)
colnames(psd) <- gsub(pattern = "__", replacement = "-", x = colnames(psd))
HTH, Vladimir
Hello!
I had performed several analysis using phyloseq_to_df without problem, but now I am having an error: "Error: Sample names in 'physeq' could not be automatically converted to the syntactically valid column names in data.frame (see 'make.names'). Consider renaming with 'sample_names'.
The sample names appear to have no ivalid character (they are just numbers).
Any suggestions? Thank you so much!