HU,ZHENGJUN
2007-Oct-19 20:40 UTC
[R] Help deeded: Does a R graphical function return something special?
Hi All, When I tried to catch a returned value from a R graphical function or command (e.g., plot, lines, points, abline, title, xyplot, etc.), I always get a NULL value if it is executed correctly. For example: x <- c(1,2,3,4,5,9,13,19,36) plot.Comm <- plot(x) # plot.Comm <- try(eval(plot(x))) then plot.Comm has a NULL value. Obviously, this is not a good way to check if or not it is a graphical function or command since plot.Comm <- NULL also lets plot.Comm be NULL. Does anyone knows: (1) that a R graphical function or command (e.g., plot, lines, points, abline, title, xyplot, etc.) could return something special if it is run correctly, which is different from those returned from executing any R non-graphical functions or commands? (2) that there is an easy way for a R programmer to know that a R function or command is a graphical one before executing it? Thank you very much for the help in advance. Have a good weekend! Howard
jim holtman
2007-Oct-19 21:04 UTC
[R] Help deeded: Does a R graphical function return something special?
What exactly are you trying to determine? You can look at the help page for a function to see what, if any, value is returned. If you are 'try'ing to catch an error, then the following might help:> x <- plot(0) > xNULL> x <- plot()Error in plot() : argument "x" is missing, with no default> xNULL> str(x)NULL> x <- try(plot())Error in plot() : argument "x" is missing, with no default> str(x)Class 'try-error' chr "Error in plot() : argument \"x\" is missing, with no default\n">What you want to do to see if there is an error is to: if (class(x) =='try-error')..... this will do it. You can not just check the 'value'. On 10/19/07, HU,ZHENGJUN <hhu at ufl.edu> wrote:> Hi All, > > When I tried to catch a returned value from a R graphical > function or command (e.g., plot, lines, points, abline, title, > xyplot, etc.), I always get a NULL value if it is executed > correctly. For example: > x <- c(1,2,3,4,5,9,13,19,36) > plot.Comm <- plot(x) # plot.Comm <- try(eval(plot(x))) > > then plot.Comm has a NULL value. Obviously, this is not a good way > to check if or not it is a graphical function or command since > plot.Comm <- NULL also lets plot.Comm be NULL. > > Does anyone knows: > > (1) that a R graphical function or command (e.g., plot, lines, > points, abline, title, xyplot, etc.) could return something > special if it is run correctly, which is different from those > returned from executing any R non-graphical functions or > commands? > > (2) that there is an easy way for a R programmer to know that a R > function or command is a graphical one before executing it? > > Thank you very much for the help in advance. > Have a good weekend! > Howard > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Deepayan Sarkar
2007-Oct-19 21:12 UTC
[R] Help deeded: Does a R graphical function return something special?
On 10/19/07, HU,ZHENGJUN <hhu at ufl.edu> wrote:> Hi All, > > When I tried to catch a returned value from a R graphical > function or command (e.g., plot, lines, points, abline, title, > xyplot, etc.), I always get a NULL value if it is executed > correctly. For example: > x <- c(1,2,3,4,5,9,13,19,36) > plot.Comm <- plot(x) # plot.Comm <- try(eval(plot(x))) > > then plot.Comm has a NULL value. Obviously, this is not a good way > to check if or not it is a graphical function or command since > plot.Comm <- NULL also lets plot.Comm be NULL. > > Does anyone knows: > > (1) that a R graphical function or command (e.g., plot, lines, > points, abline, title, xyplot, etc.) could return something > special if it is run correctly, which is different from those > returned from executing any R non-graphical functions or > commands? > > (2) that there is an easy way for a R programmer to know that a R > function or command is a graphical one before executing it?You should always consult the appropriate help page. ?lines mentions no return value (and returns NULL), but ?hist and ?xyplot do describe non-trivial return values. -Deepayan
Apparently Analagous Threads
- You are right and the problem is solved. Re: about the possible errors in Rgraphviz Package
- about the possible errors in Rgraphviz Package
- How to catch a R error in R code
- Case sensitivity in :addresses in sieve vacation scripts
- [PATCH v1 0/2] Support dropping of capabilities from early userspace.