Re: [Rd] R C api for 'inherits' S3 and S4 objects

2019-11-01 Thread Michael Lawrence via R-devel
If your goal is to perform multithreaded computations, why not perform
all necessary interactions with R upfront and then compute only on
primitives? It would help for us to understand your use case.

On Fri, Nov 1, 2019 at 4:26 AM Jan Gorecki  wrote:
>
> Dear R developers,
>
> Motivated by discussion about checking inheritance of S3 and S4
> objects (in head matrix/array topic) I would light to shed some light
> on a minor gap about that matter in R C API.
> Currently we are able to check inheritance for S3 class objects from C
> in a robust way (no allocation, thread safe). This is unfortunately
> not possible for S4 classes. I would kindly request new function in R
> C api so it can be achieved for S4 classes with no risk of allocation.
> For reference mentioned functions below. Thank you.
> Jan Gorecki
>
> // S3 inheritance
> bool INHERITS(SEXP x, SEXP char_) {
>   SEXP klass;
>   if (isString(klass = getAttrib(x, R_ClassSymbol))) {
> for (int i=0; i   if (STRING_ELT(klass, i) == char_) return true;
> }
>   }
>   return false;
> }
> // S4 inheritance
> bool Rinherits(SEXP x, SEXP char_) {
>   SEXP vec = PROTECT(ScalarString(char_));
>   SEXP call = PROTECT(lang3(sym_inherits, x, vec));
>   bool ans = LOGICAL(eval(call, R_GlobalEnv))[0]==1;
>   UNPROTECT(2);
>   return ans;
> }
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Michael Lawrence
Senior Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-7760
micha...@gene.com

Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] R C api for 'inherits' S3 and S4 objects

2019-11-01 Thread Jan Gorecki
Dear R developers,

Motivated by discussion about checking inheritance of S3 and S4
objects (in head matrix/array topic) I would light to shed some light
on a minor gap about that matter in R C API.
Currently we are able to check inheritance for S3 class objects from C
in a robust way (no allocation, thread safe). This is unfortunately
not possible for S4 classes. I would kindly request new function in R
C api so it can be achieved for S4 classes with no risk of allocation.
For reference mentioned functions below. Thank you.
Jan Gorecki

// S3 inheritance
bool INHERITS(SEXP x, SEXP char_) {
  SEXP klass;
  if (isString(klass = getAttrib(x, R_ClassSymbol))) {
for (int i=0; ihttps://stat.ethz.ch/mailman/listinfo/r-devel