How to stop R creating syntactically correct names
1
2
Entering edit mode
8.4 years ago
emmapead2 ▴ 60

Hello,

So I have a list of metabolites and peak intensities which I'm bring into R for analysis then I need to bring it out again. Unfortunately, R changes the names of my metabolites so that they are syntactically correct

eg. L-Leucine is changed to L.Leucine

this poses a significant hurdle as if I'm to compare to other resources for my analysis the metabolite won't be recognised because of the syntax. The problem is further amplified when the metabolite names get more complicated. I've tried looking for patterns to change the names using awk etc but theres no definitive pattern and I have LOTS of data.

Is there a way to stop R doing this or any method to undo the changes when I bring the data out of R?

(I've already tried check.names = F, and this does not work)

R metabolomics • 2.8k views
ADD COMMENT
2
Entering edit mode

check.names=F works for me. Also, this is probably better asked at stackoverflow

ADD REPLY
1
Entering edit mode

I may try there, but thought I'd post on here just in case anyone has done this kind of analysis with metabolomics data specifically and may have advice.

ADD REPLY
1
Entering edit mode

Regarding there being no definitive pattern, the details are given at the make.names help page

ADD REPLY
1
Entering edit mode

I've tried this already but make.names does not like replicates. It will add ".1" on the end. This is still an issue as I'm comparing multiple sets which may have the same metabolites and comparing e.g L.Leucine.1 in one file to L.Leucine.1 in another does not necessarily mean they are identified as the same. To add another lovely layer of confusion to it all i can't just remove the ".1" as some of the metabolites have ".1" in their name

ADD REPLY
0
Entering edit mode

For completeness, could you please add your R code in your question?

ADD REPLY
3
Entering edit mode
8.4 years ago
ablanchetcohen ★ 1.2k

When reading the information from a file, check.names = FALSE works for me, with either read.table of fread. If during further processing, the names have to be converted to syntactically valid names, I just store the names after reading them, and then restore the names right before outputting them, at the end of the processing. Although, you could try and convert the syntactically correct names to the original names using a reverse function, it is much simpler to just store the original names when you first read them. Restoring them before outputting them is then trivial.

ADD COMMENT
1
Entering edit mode

Ahhhhhh so I think my problem has been is that I'm actually reading it from excel (nobody shout at me, I was given the data like this :D) so it stores the names of my metabolites as row names which really need to be different for anything further to work. So I guess if I just store my metabolites as a dataframe then allow R to change the rows so it understands them then before i put it out just cbind it all? This what you mean?

ADD REPLY
2
Entering edit mode

I don't believe row names need to respect the R syntax for variable names. For the column names in Excel files, some packages like openxlsx do come with the option check.names = FALSE, so it makes no difference whether you read the data from an Excel file or a text file. If, for some reason, the row names are being transformed, you can also store the rownames as a column, in which case any string will be accepted. For further downstream processing where you would use the row names as variables names, just use the same simple strategy, store the names before processing, and restore them before outputting the names.

ADD REPLY
1
Entering edit mode

Thanks very much, I'll give it a go. Just strange how check.names = F regardless of which package I use to bring in the file just does not work at all, especially if their are replicates. Which is a major issue as I need to keep them but also be able to trace back their corresponding values which I've described why its an issue in one of my above comments

ADD REPLY

Login before adding your answer.

Traffic: 1591 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6