[ESS] ess-execute and ess-command

Erik Iverson iverson at biostat.wisc.edu
Sat Jan 31 02:45:47 CET 2009


Dan -

I have just recently started studying the ESS code (as a vehicle for learning 
emacs lisp), so process everything in this message with that in mind.

Dan Davison wrote:
> I am constructing R expressions in elisp and evaluating them with ess-execute.
> 
> When calling ess-execute from elisp code, how can I detect if an error
> occurred in R? (At the moment I can only think of something very
> clumsy involving try() and writing to file).

Perhaps we need to know what you're trying to do with a bit more detail?  "An 
error occurring in R" isn't a very well-defined concept, as far as I know.  What 
kind of error?  Functions can return values that indicate an error happened. 
For example, at the R prompt, type

 > str(no_object_by_this_name)
Error in str(no_object_by_this_name) :
   object "no_object_by_this_name" not found	

If this is the the kind of thing you want to detect, you can do it by using the 
ess-command function with the optional buf argument, and then using something 
like the string-match function to check for the word "Error" in the buffer text. 
(See the file ess-rdired.el in the ESS sources for an example of a similar 
approach to getting return values of R functions).

I'm sure there are subtleties that this approach will not work with, but it 
might be good enough for what you want.

Maybe there's a better way, too?

> 
> When should one use ess-execute and when ess-command?

This I do not know, hopefully someone else can clarify why these two different 
functions exist.  It's a question of mine, too.

Best,
Erik Iverson




More information about the ESS-help mailing list