Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - how can I dump contents of file to console output?

Tags:

r

I simply want to read a file and output it in the console. print( readLines(...) ) is the best I can do so far, but I don't want a line-by-line identifier, I just want the file as-is.

like image 312
SFun28 Avatar asked Apr 29 '11 15:04

SFun28


2 Answers

You could use system to call a system command.

system("cat yourfile.txt")
like image 76
Aaron left Stack Overflow Avatar answered Sep 29 '22 04:09

Aaron left Stack Overflow


Here's an elegant way using dplyr

library(dplyr)
readLines("init.R") %>% paste0(collapse="\n") %>% cat

or with base R

cat(paste0(readLines("init.R"), collapse="\n"))

remember to replace init.R with the file path myfolder/myfile.R

like image 25
stevec Avatar answered Sep 29 '22 04:09

stevec