I am a Stata user trying to learn R.
I have a couple of lengthy folder paths which, in my Stata code, I stored as local macros. I have multiple files in both those folders to use in my analysis.
I know, in R, I can change the working directory each time I want to refer to a file in one of the folders but it is definitely not a good way to do it. Even if I store the folder paths as strings in R, I can't figure out how to refer to those. For example, in Stata I would use `folder1'.
I am wondering if trying to re-write Stata code line by line in R is not the best way to learn R.
Can someone please help?
Maybe you want file.path()
?
a <- "c:"
b <- "users"
c <- "charles"
d <- "desktop"
setwd(file.path(a,b,c,d))
getwd()
#----
[1] "c:/users/charles/desktop"
You can wrap source
or read.XXX
or whatever else around that to do what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With