[R] help in using gsub and ?

ravi rv15i at yahoo.se
Fri Jul 31 15:30:08 CEST 2009


Hi all,
I would like to strip the R prompt from a series of code lines and copy the resulting text into a R script. For example, consider the following :
#####
str1<-"
> library(MASS)
> data(Cars93)
> attach(Cars93)
> imosaic(data.frame(AirBags,Cylinders,Origin))"
str2<-gsub('>','',str1)
######
This gives, as expected . 
> str2
[1] "\n library(MASS)\n data(Cars93)\n attach(Cars93)\n imosaic(data.frame(AirBags,Cylinders,Origin))"

How can I now activate the newline character, "\n", so that I get the following print-out :
library(MASS)
data(Cars93)
attach(Cars93)
imosaic(data.frame(AirBags,Cylinders,Origin))
I would appreciate any help that I can get.
Thanking you,
Ravi




More information about the R-help mailing list