Skip to content
Prev 8402 / 12125 Next

[R-pkg-devel] Error checking in an independent C code and printing (perror, printf, etc.)

I was hoping that you will tell me that R takes control of the C's 
stderr and stdout.
That would make stuff easier. But I guess that is not really possible.

I went the way suggested before and created an enum of error codes and a 
(static) const char* array of error messages.
When reading about error checking in C, that looked like the most 
wholesome way. First time using the dreadful "goto",
looks like it makes sense to free resources. 
(https://stackoverflow.com/a/59221452/4868692)

It still looks a bit ugly compared to simple "throw" (i.e., too much 
code noise),
and I now understand where the Java's checked exceptions are coming from.
And somehow, now that I am thinking about it, I am getting used to it.

Thanks again.
I hope I am responding correctly ("respond all") and not spamming people.

ps.: The .Call interface is easier than it seems, the R documentation is 
not very good and spread the information a bit too much over many pages.
Once I got my .Call(c_hello_world) (including all the linking, info 
about the C_ naming and speed, the 
`tools::package_native_routine_registration_skeleton` was nice),
it all went quite nicely from there. Particularly, when to use PROTECT() 
is not clear (new SEXP objects, but not required if they are just 
interfaced with INTEGER(), REAL()
or VECTOR_ELT).

The overview: 
https://stat.ethz.ch/pipermail/r-devel/attachments/20120323/a13f948a/attachment.pdf
was also really helpful and should be IMHO part of official documentation.

An example how to work with named list (e.g., an S3 class), where 
subsetting is done by name and not by position,
would be really useful.

-- Jirka
On 9/7/22 04:52, Ivan Krylov wrote: