Hi List,
I am new to R, this may be simple.
I want to store directory path as parameter which in turn to be used while
reading and writing data from csv files.
How I can use dir defined in the below mentioned example while reading the
csv file.
Example:
dir <- "C:/Users/Desktop" #location of file
temp_data <- read.csv("dir/bs_dev_segment_file.csv")
If I run this it will show errors:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'dir/bs_dev_segment_file.csv': No such file or directory
Regards,
-Ajit
--
View this message in context: http://r.789695.n4.nabble.com/Putting-directory-path-as-a-parameter-tp4043092p4043092.html
Sent from the R help mailing list archive at Nabble.com.
Putting directory path as a parameter
4 messages · aajit75, Joshua Wiley, michael.weylandt at gmail.com (R. Michael Weylandt +1 more
Hi Aajit, try using the ?paste function to combine the variable with your directly and the filename into one string, and then pass that to read.csv() or whatever paste(dir, "/bs_dev_segment_file.csv", sep = '') HTH, Josh
On Tue, Nov 15, 2011 at 6:12 AM, aajit75 <aajit75 at yahoo.co.in> wrote:
Hi List,
I am new to R, this may be simple.
I want to store directory path as parameter which in turn to be used while
reading and writing data from csv files.
How I can use dir defined ?in the below mentioned example while reading the
csv file.
Example:
dir <- "C:/Users/Desktop" #location of file
temp_data <- read.csv("dir/bs_dev_segment_file.csv")
If I run this it will show errors:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
?cannot open file 'dir/bs_dev_segment_file.csv': No such file or directory
Regards,
-Ajit
--
View this message in context: http://r.789695.n4.nabble.com/Putting-directory-path-as-a-parameter-tp4043092p4043092.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
Try pasting them together like paste(dir, "...") You may need to use the collapse argument. Alternatively, change your working directory to dir with setwd(). M
On Nov 15, 2011, at 9:12 AM, aajit75 <aajit75 at yahoo.co.in> wrote:
Hi List,
I am new to R, this may be simple.
I want to store directory path as parameter which in turn to be used while
reading and writing data from csv files.
How I can use dir defined in the below mentioned example while reading the
csv file.
Example:
dir <- "C:/Users/Desktop" #location of file
temp_data <- read.csv("dir/bs_dev_segment_file.csv")
If I run this it will show errors:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'dir/bs_dev_segment_file.csv': No such file or directory
Regards,
-Ajit
--
View this message in context: http://r.789695.n4.nabble.com/Putting-directory-path-as-a-parameter-tp4043092p4043092.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
file.path() is much better for this than paste(), e.g. dir <- "C:/Users/Desktop" pathname <- file.path(dir, "bs_dev_segment_file.csv") temp_data <- read.csv(pathname) /Henrik On Tue, Nov 15, 2011 at 10:08 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> <michael.weylandt at gmail.com> wrote:
Try pasting them together like paste(dir, "...") You may need to use the collapse argument. Alternatively, change your working directory to dir with setwd(). M On Nov 15, 2011, at 9:12 AM, aajit75 <aajit75 at yahoo.co.in> wrote:
Hi List,
I am new to R, this may be simple.
I want to store directory path as parameter which in turn to be used while
reading and writing data from csv files.
How I can use dir defined ?in the below mentioned example while reading the
csv file.
Example:
dir <- "C:/Users/Desktop" #location of file
temp_data <- read.csv("dir/bs_dev_segment_file.csv")
If I run this it will show errors:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
?cannot open file 'dir/bs_dev_segment_file.csv': No such file or directory
Regards,
-Ajit
--
View this message in context: http://r.789695.n4.nabble.com/Putting-directory-path-as-a-parameter-tp4043092p4043092.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.