2012-04-09 27 views
1

是否可以使用R打印文件的內容(支持r,tex,txt,rnw等擴展名)?使用R打印文件的內容(支持r,tex,txt,rnw等擴展名)?

重現文件:

sink('myFile') 
cat('\nThis is some text') 
cat('\n') 
cat('\nEnd of file') 
sink() 

現在我正在尋找R中的功能,打印R的內容...

>PRINT_FILE_CONTENT('myFile') 
This is some text 
End of file 
> 

我希望我很清楚。我會感謝任何幫助?

回答

2

這似乎工作:

cat(readLines("myFile"),sep="\n") 

雖然我沒有得到

Warning message: 
In readLines("myFile") : incomplete final line found on 'myFile' 

末...如果你喜歡,你可以把它包在suppressWarnings()

+2

考慮在'readLines'內使用'warn = FALSE'。 – flodel 2012-04-10 00:49:08