Skip to content
Back to formatted view

Raw Message

Message-ID: <BANLkTinFHDQaXY6Em73P=Rnd737QsSitfQ@mail.gmail.com>
Date: 2011-06-01T20:06:10Z
From: Yang Zhang
Subject: Plotting from functions
In-Reply-To: <BANLkTik_2A4VovSh_jQjROPCgFqk1zTVvQ@mail.gmail.com>

On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang <yanghatespam at gmail.com> wrote:
> I can plot to png's fine when i run this directly from the top-level
> script/console:
>
> png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()
>
> But for some reason it's not working when that's in a function:
>
> (function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})()
>
> I suspect this is because the qplot's return value must be "returned"
> to the top-level, because this works:
>
> (function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off()
>
> Any hints on how I can plot from within a function? ?Thanks in advance.
>

Actually, just found that things work if I do:

print(qplot(...))

Is this just what you need to do to plot from within functions?