I am writing a script in R to perform automated analysis of some files we receive as output from a lab instrument.
The final output of my script is a wide .csv file with multiple headers, and to better suit the end user, the headers are properly formatted as they would expect.
For example, one of the parameter is the following: 'dm/ds_max'.
Everything works fine when this parameter is written as variable in the table header or when I have to use this parameter as variable in ggplot (for example to automatically generate a plot title with dm/ds_max), but becomes problematic when I am trying to use the name of the variable in the paste() command to save the graph.
As you can imagine, the / in the paste() is interpreted as directory delimiter and the files are then saved in the wrong folder.
For example, when the variable name is colour, the plot are properly saved in the proper folder as img/colour.jpg. When the variable name is dm/ds_max, the file is saved as img/dm/ds_max.jpg, putting it in a non-existing folder.
Is there a way -beside changing the name of the variable- to bypass this conflict between writing tables in a nice human readable format and making automated plots with the same variable?
Thank you
I am reading some files into R with a "for loop" and naming them based on the looping index. I have used the assign fucntion to dynamically name one data frame for each file being read as follows:
for (i in 1:10){
assign(paste0("df",i),read_csv(paste0("file",i,".csv")))
}
This works fine. However, while inside the for loop, I also want to do some other operations to the data frame, but I dont know how to refer to it given that the name is changing as the loop progresses.
I want to add to the loop something along the lines of:
names(paste0("df",i)) <- make.names(names(paste0("df",i)))
I want to execute the above command but I don't know how to properly pass the changing data frame name to the names() function.
Thanks in advance,
MR
for one of my projects I will need to import the dataset (csv-File) outside of R and then assign it from the Ruby side of the project in R (this will be done with rinruby and already works).
In my R-Script I now need to create a list out of that csv file.
The variable contains an escaped string that contains the original csv.
data <- "\"\",\"futime\",\"fustat\",\"age\",\"resid.ds\",\"rx\",\"ecog.ps\"\n\"1\",59,1,72.3315,2,1,1\n\"2\",115,1,74.4932,2,1,1\n\"3\",156,1,66.4658,2,1,2\n\"4\",421,0,53.3644,2,2,1\n\"5\",431,1,50.3397,2,1,1\n\"6\",448,0,56.4301,1,1,2\n\"7\",464,1,56.937,2,2,2\n\"8\",475,1,59.8548,2,2,2\n\"9\",477,0,64.1753,2,1,1\n\"10\",563,1,55.1781,1,2,2\n\"11\",638,1,56.7562,1,1,2\n\"12\",744,0,50.1096,1,2,1\n\"13\",769,0,59.6301,2,2,2\n\"14\",770,0,57.0521,2,2,1\n\"15\",803,0,39.2712,1,1,1\n\"16\",855,0,43.1233,1,1,2\n\"17\",1040,0,38.8932,2,1,2\n\"18\",1106,0,44.6,1,1,1\n\"19\",1129,0,53.9068,1,2,1\n\"20\",1206,0,44.2055,2,2,1\n\"21\",1227,0,59.589,1,2,2\n\"22\",268,1,74.5041,2,1,2\n\"23\",329,1,43.137,2,1,1\n\"24\",353,1,63.2192,1,2,2\n\"25\",365,1,64.4247,2,2,1\n\"26\",377,0,58.3096,1,2,1"
And I would like to convert this to a R-List.
So my approach is basically to call read.csv(data_as_string) but unfortunately the signature is read.csv(file_where_data_lies).
How can this be done?
Thanks so much!
As Therkel mentioned above, myfunc(file = textConnection(data)) did exactly what I was about to do. Thanks!