You can leave your script as it was and use source()'s print.eval=TRUE or echo=TRUE arguments to get the autoprinting done as it is at the command line (echo=TRUE also prints the commands).
E.g., for the file "/tmp/x.R" containing the 2 lines d <- mtcars[,c("am","gear","hp","mpg")] summary(lm(data=d, mpg~.)) I get > source("/tmp/x.R") or > source("/tmp/x.R", echo=TRUE) # this is the only line I typed > d <- mtcars[,c("am","gear","hp","mpg")] > summary(lm(data=d, mpg~.)) Call: lm(formula = mpg ~ ., data = d) [... many output lines elided ...] F-statistic: 34.83 on 3 and 28 DF, p-value: 1.377e-09 or > source("/tmp/x.R", echo=FALSE, print.eval=TRUE) # only line I typed Call: lm(formula = mpg ~ ., data = d) [... many output lines elided ...] F-statistic: 34.83 on 3 and 28 DF, p-value: 1.377e-09 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of John Kane > Sent: Thursday, February 07, 2013 10:57 AM > To: James Jong; r-help@r-project.org > Subject: Re: [R] Sourcing my file does not print command outputs > > From ?source > "Note that running code via source differs in a few respects from entering it > at the R > command line. Since expressions are not executed at the top level, > auto-printing is not > done. So you will need to include explicit print calls for things you want to > be printed" > > John Kane > Kingston ON Canada > > > > -----Original Message----- > > From: ribonucle...@gmail.com > > Sent: Thu, 7 Feb 2013 13:36:56 -0500 > > To: r-help@r-project.org > > Subject: [R] Sourcing my file does not print command outputs > > > > I looked at the documentation of source() and summary(), and I could not > > find the reason why calling something like: > > > >> summary(resamps) > > > > from the command line, works (it prints the summary) > > > > whereas calling > > > > summary(resampls) > > > > from a file that I source with source("my_file.r") does not print > > anything. > > > > How can I get summary(resamps) to print when I source a file with this > > command? > > > > Thanks, > > > > James > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > ____________________________________________________________ > FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! > > ______________________________________________ > 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. ______________________________________________ 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.