[R] Simple programming problem with 'with' or 'data ='
Adaikalavan Ramasamy
a.ramasamy at imperial.ac.uk
Wed Aug 27 21:09:07 CEST 2008
with(gdsgraph, boxplot(BReT3T5T ~ gds3lev)) is equivalent to
boxplot(gdsgraph$BReT3T5T ~ gdsgraph$gds3lev), so all the terms are found.
gds1lev is not found within the scope of the function gdsbox(). This
function has too many hard codings to be of much use generically.
Consider rewriting it as (untested function)
gdsbox <- function(y, x, data, main.title=NULL, ...){
if(is.null(main.title)){
main.title <- paste('Boxplot of', substitute(y), "for GDS groups") }
boxplot( data$y ~ data$x, main=main.title, ... )
}
but why bother when you call the more robust, well tested and well
documented boxplot() ?
If you still want help, can you give a simple reproducible example?
Regards, Adai
Peter Flom wrote:
> Hello
>
> I wrote a simple program to modify a boxplot:
>
> <<<
>
> gdsbox <- function(indvar){
> boxplot(indvar~gds3lev,
> main = paste('Boxplot of', substitute(indvar), "for GDS groups"),
> names = c('1', '3', '4, 5, 6'))
> }
>
>
> If I attach the dataframe gdsgraph, this works fine. However, I've been warned against attach. When I tried to run this program using 'with', it did not work.
>
> e.g.
>
> with(gdsgraph, gdsbox(BReT3T5T))
>
> produced an error that gds3level was not found
>
> but if I try
>
> with(gdsgraph, boxplot(BReT3T5T~gds3lev))
>
> it works fine.
>
> Similar problems occurred when I tried to use data =
>
> What am I missing?
>
> Thanks
>
> Peter
>
>
>
>
> Peter L. Flom, PhD
> Brainscope, Inc.
> 212 263 7863 (MTW)
> 917 488 7176 (ThF)
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list