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

Steven Scott @teve@the@b@ye@|@n @end|ng |rom gm@||@com
Tue Sep 6 18:27:08 CEST 2022


All software engineering problems are solved by an additional layer of
indirection!  ;-)

Introduce a function called "process_error".  Include one implementation
for your standalone C library.  Include another R-specific one when using
your C library as part of an R package.

On Tue, Sep 6, 2022 at 9:23 AM Jiří Moravec <jiri.c.moravec using gmail.com>
wrote:

> Hello,
>
> this is my first time writing C code that interacts with R.
> To make my C code more modular, reusable, and easier to test with
> unittests, I split my code into:
>
> a) code that does stuff
> b) code that interfaces between a) and R.
>
> Only the b) imports the R headers, a) is completely independent of R
> (and potentially shared between different projects).
>
> That brings me to a problem: How to do error handling in C without the
> use of various C-specific print functions R-specific print functions?
>
> The C-specific print functions raise a CRAN note:
>
> Compiled code should not call entry points which might terminate R nor
> write to stdout/stderr instead of to the console, nor use Fortran I/O
> nor system RNGs
>
> But R(C) print functions cannot be used without importing particular
> header,
> which would induce otherwise another dependency, and tie it closely with R.
>
> This is my first time writing into mailing list, hopefully I am doing
> everything ok.
>
> Thanks everyone!
>
> -- Jirka
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list