[英]Breaking R code to the next line for file paths
Why this works: 工作原理:
PC<-read.csv('./public-transportation/san-francisco/passenger-count.csv', header=TRUE)
But the following doesn't work in R: 但是以下在R中不起作用:
inputFile <-paste('./public-transportation/',
'san-francisco/passenger-count.csv')
PC<-read.csv(inputFile, header=TRUE)
All I am doing is passing a variable that holds the filename? 我正在做的是传递一个保存文件名的变量? Sorry, I am relatively new to R. This is kinda baffling me a bit. 抱歉,我是R的新手。这有点让我感到困惑。 Any help is appreciated.. 任何帮助表示赞赏。
This doesn't work because the default separator in paste
is a space. 这不起作用,因为paste
的默认分隔符是空格。 So you need to set sep=""
, use paste0
, or use file.path
. 因此,您需要设置sep=""
,使用paste0
或使用file.path
。
# paste with sep=""
inputFile <- paste('./public-transportation/',
'san-francisco/passenger-count.csv', sep="")
# paste0
inputFile <- paste0('./public-transportation/',
'san-francisco/passenger-count.csv')
# file.path
inputFile <- file.path('./public-transportation/',
'san-francisco/passenger-count.csv')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.