csv - How to access to specify file in subfolder without change working directory In R? -
csv - How to access to specify file in subfolder without change working directory In R? -
in r, want access file in subfolder. don't want alter working directory move back. lost time , long.
for exmaple, working on /home/phuong
folder. here tree construction of phuong.
phuong-> data1, data2, data3. data1-> abc.csv, def.csv, script1.r data2-> bond.csv, option.csv, pricing.r data3->.....
so want load info in abc.csv, def.csv , run code in pricing.r.
so if utilize code setwd
, create me lost many time , code stupid, this:
setwd("/home/phuong/data1" ); read.csv("abc.csv"); read.csv("def.csv"); setwd("/home/phuong/data2" ); source("pricing.r")
i lost lot of times move folder folder of them in same folder home/phuong/
. need way access file in subfolder without setwd
command. please help me , thks.
assuming working directory /home/hermie
, want load .csv
file directory below current wd (let's /home/hermie/data
), can this:
setwd('/home/hermie') mydata <- read.csv('./data/mycsvfile.csv')
of course of study navigate "upwards" in directory tree. let's want load file in bob's home directory (/home/bob
). can follows:
setwd('/home/hermie') data_from_bob <- read.csv('../bob/otherdatafile.csv') # of course, work # if can read # files directory
hope helps.
update
somehow think want write solution you... , propose this:
> setwd('/home/phuong') > data_abc <- read.csv('./data1/abc.csv') > data_def <- read.csv('./data1/def.csv') > source('./data2/pricing.r')
is so dificult write this? have write much more if changed wd on every step of way.
and, sugestion on symlinks, on bash terminal this:
$ cd /home/phuong $ ln -s ./data1/abc.csv data1_abc.csv $ ln -s ./data1/def.csv data1_def.csv $ ln -s ./data2/pricing.r pricing.r
and then, r:
> setwd('/home/phuong') > data_abc <- read.csv('data_abc.csv') > data_def <- read.csv('data_def.csv') > source('pricing.r')
r csv
Comments
Post a Comment