Hello,

I'm working on a function envvars() which I'd like to get, set, and
remove environment variables in a manner similar to options(). At the
R level, I have this function:

envvars <- function (...)
.External2(C_envvars, pairlist(...))

and then at the C level:

#define set_R_Visible(X) (eval( (X) ? R_NilValue :
lang1(install("invisible")) , R_BaseEnv))

SEXP do_envvars(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    // details omitted
    set_R_Visible(visible);  /* 0 or 1 for invisible or visible return */
    UNPROTECT(nprotect);
    return value;
}

This seems to work as intended, it returns invisibly when getting 0
environment variables (setting/unsetting are not counted as getting)
and returns visibly when getting >= 1 environment variables.

My concern is that this solution feels hack-ish, like it could easily
break in a future update. So, does anyone know of a more official way
to change the visibility of a return value from a C function? Thank
you!

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to