r - Reading Data from different locations through a function -
i pretty new r , struggling below scenario : need write function reads data different locations on pc(like downloads,documents,desktop etc). each file in these locations have unique id. function take id , location arguments. :
onefunc <- function(directory,id) { y <- read.csv("directory/id") }
i need pass directory , id read function. above code throws error - cannot open file 'directory/id': no such file or directory. need pass in read.csv exactly?
what have right inside function string (sequence of characters). r not recognize these variables. need variables directory
, id
string. host of options available that:
sprintf('%s/%s', directory, id)
paste(directory, id, sep = '/')
file.path(directory, id)
, meant constructing file paths. other functions generic string building functions. recommend using function in case specific situation, , work across platforms.
you can feed string read.csv
perform actual reading.
Comments
Post a Comment