我只是想读取文件并将其输出到控制台中。到目前为止,print(readLines(...))是我能做的最好的事情,但是我不需要逐行的标识符,我只是希望文件保持原状。
?cat
可能正是您想要的。writeLines
代替print
。 con
的默认writeLines
为stdout()
,因此writeLines(readLines(...))
听起来不错。 请参见?writeLines
。
system
调用系统命令。system("cat yourfile.txt")
readChar
可能会有所帮助:cat(readChar(filename, 1e5))
dplyr
的一种优雅方式>library(dplyr)
readLines("init.R") %>% paste0(collapse="\n") %>% cat
或带底数的R
cat(paste0(readLines("init.R"), collapse="\n"))
请记住用文件路径init.R
替换myfolder/myfile.R