[R] Unable to Plot using headers.

stephen's mailinglist account stephen4mailinglists at googlemail.com
Fri May 27 21:39:07 CEST 2011


On 27 May 2011 20:25, Jonathan Daily <biomathjdaily at gmail.com> wrote:
> I would caution against using attach(), however, if you are not in an
> interactive session. In functions and scripts, errors can often cause
> the interpreter to exit before the detach(), leaving your data on the
> search path. 99% of all attach/detach cases can be handled by ?with
> and ?within. The issue with attach can be seen in this example:
>
> dat <- data.frame(a = 1, b = 2)
>
> test <- function(x){
> attach(dat)
> if(x) stop("STOP")
> print(a)
> print(b)
> detach(dat)
> }
>
> a
> test(F)
> a
>
> a
> test(T)
> a
>
>
fair point
I tend to opt for the dat$a or dat$b form personally anyway, but was
defaulting back to some of the instructional texts I read early on.

-- 
Stephen



More information about the R-help mailing list