[R] Thank you, and your suggestion works

HU,ZHENGJUN hhu at ufl.edu
Wed Oct 10 17:10:14 CEST 2007


Hi Jim,

  What you told me works well.

  I have tried using 'eval(parse(text="1:20 = x"))' as well as 
'try(parse(text="1:20 = x"))' before but not using eval anfd try 
functions together. I just added try function following your 
suggestion, e.g. 'try(eval(parse(text="1:20 = x")))'and then it 
worked well.

  Thank you very much for the nice and instant help.
  Howard


On Wed Oct 10 10:02:39 EDT 2007, jim holtman <jholtman at gmail.com> 
wrote:

> You need to follow the posting guide and provide commented, 
> minimal,
> self-contained, reproducible code.
> 
> I can only guess at what your code looks like, but the following
> catches the error:
> 
>> z <- try(eval(parse(text="1:20 <- x")))
> Error in eval(expr, envir, enclos) : object "x" not found
>> str(z)
> Class 'try-error'  chr "Error in eval(expr, envir, enclos) : 
> object
> \"x\" not found\n"
>> z <- try(eval(parse(text="x <- 1:20")))
>> str(z)
>  int [1:20] 1 2 3 4 5 6 7 8 9 10 ...
>> 
> 
> 
> On 10/10/07, HU,ZHENGJUN <hhu at ufl.edu> wrote:
>> Hi All,
>> 
>>  I entered a R statement, e.g. 1:20 = x or log("a") on an HTML
>> form and passed it to a R-CGI script. Obviously, neither of both
>> is a correct R statement or expression. However, my R-CGI script
>> could not return and report the error message to the Web site 
>> even
>> though it received the statement. I tried to use some R built-in
>> functions of try, tryCatch, eval, expression, as.expression,
>> parse, deparse, etc. None of them worked.
>> 
>>  Note: when a statement is correct, i.e. x = 1:20 or log(2), the
>> same script returned and reported the R output to the Web site.
>> 
>>  If any of you has the experience about the matter or topic,
>> could you please tell me how to catch a R error in this case?
>> 
>>  Thank you very much for the help in advance.
>>  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?
> 
> 



--
HU,ZHENGJUN



More information about the R-help mailing list