I want to write generic code which takes input from user, but when I run:
directory_name <- readline(prompt=" Enter the directory")
Enter the directory C:\\Users\\ANKIT\\Documents
It shows directory name like this (with double-backslashes)
directory_name "C:\\\\Users\\\\ANKIT\\\\Documents"
And how to use this directory name to load .csv file?
Use read.csv and paste0:
directory_name <- readline(prompt=" Enter the directory")
Enter C:\\Users\\griffinevo\\temporaryRfiles
read.csv(paste0(directory_name, "\\filename.csv"))
We can use paste0
to paste
the file with the object directory_name
directory_name <- readline(prompt=" Enter the directory")
dat <- read.csv(paste0(directory_name, "\\mpg_data.csv"))
Or with paste
and specify the sep
dat <- read.csv(paste(directory_name, "mpg_data.csv", sep="\\"))
dim(dat)
#[1] 79 16
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.