Tal Galili
2011-Sep-21 13:03 UTC
[R] Making ?source act as if it is run through the terminal
Hello dear R help, The motivation for my question is wanting to run HTMLStart {R2HTML package} from "source". *Background:* I was happy to discover the [ HTMLStart/HTMLStop, HTMLplot] functions in the R2HTML package. They allow my R code to run almost as is, but while writing most of the output (including the figures, when using HTMLplot) into an external HTML file. This method works rather well, but only when the script is running from the terminal. When I try using the code from ?source, the functions fails completely (with both output and especially with figures) I assume the reason is because of what is said in the help file: "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" *Question:* Hence my question is - can it be avoided? Can the source be set to act just as if the code were to run from the terminal? Thanks, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
R. Michael Weylandt
2011-Sep-21 16:38 UTC
[R] Making ?source act as if it is run through the terminal
Maybe some of the source() options will work. Suppose you have the following in an R file: #### junk.R #### 1:5 x = 1:10 library(ggplot2) data(VADeaths) pl <- ggplot(melt(VADeaths),aes(value, X1))+ geom_point() + facet_wrap(~X2)+ylab("") pl Then from the command line:> source("junk.R")## No output> source("junk.R, print.eval = TRUE)[1] 1 2 3 4 5 and a window displays a graph. Not sure if this will work with the HTML stuff (don't know the first thing about the package), but it seems like a start. Hope this helps, Michael Weylandt On Wed, Sep 21, 2011 at 9:03 AM, Tal Galili <tal.galili@gmail.com> wrote:> Hello dear R help, > > The motivation for my question is wanting to run HTMLStart {R2HTML package} > from "source". > > *Background:* > > I was happy to discover the [ HTMLStart/HTMLStop, HTMLplot] functions in > the > R2HTML package. > > They allow my R code to run almost as is, but while writing most of the > output (including the figures, when using HTMLplot) into an external HTML > file. > This method works rather well, but only when the script is running from the > terminal. > When I try using the code from ?source, the functions fails completely > (with > both output and especially with figures) > > I assume the reason is because of what is said in the help file: > "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" > > *Question:* > Hence my question is - can it be avoided? > Can the source be set to act just as if the code were to run from the > terminal? > > > > Thanks, > Tal > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili@gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > ---------------------------------------------------------------------------------------------- > > [[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. >[[alternative HTML version deleted]]