r - ggplot's qplot does not execute on sourcing -


let's assume have 2 source files, first 1 named example1.r , second 1 example2.r (given below).

example1.r

plot(1:10,1:10) 

example2.r

qplot(1:10,1:10) 

when source example1.r, graph drawn. not, however, when source example2.r. solution here?

(qplot in example2.r ggplot2's function)

update:

  • .r files: source's option print.eval=true lead printing behaviour of evaluation result in interactive command line.

source("script.r", print.eval=true)

  • .rnw files: knitr default emulates behaviour of interactive command line wrt. printing. note knitr can specified sweaving engine r package vignettes.


this original answer. note workaround imho obsolete (and small lazy niche only).

this famous faq 7.22: why lattice/trellis graphics not work?.

for grid graphics ggplot2 or lattice, need print graphics object in order draw it.

interactively on command line done automatically. everywhere else (inside files sourced, loops, functions, sweave chunks) need print explicitly.

print (qplot (1 : 10, 1 : 10)) 

alternatively, can redefine qplot printing:

qplot <- function (x, y = null, z = null, ...) {   p <- ggplot2::qplot (x = x, y = y, z = z, ...)   print (p) } 

(this changes axis labels x , y).

i use approach in vignettes want write code user in interactive session type it.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -