Try this:
cat(str2, "\n")
On Fri, Jul 31, 2009 at 10:30 AM, ravi <rv15i@yahoo.se> wrote:
>
> 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
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]