Macro function-like R to C

Both CHARACTER_VALUE and STRING_VALUE convert a scalar R object to a C-string (char *).

Arguments

x

a pointer SEXP, of which only the first element is used.

Value

C string, i.e., a pointer char *.

Declaration

#define CHARACTER_VALUE(x) CHAR(Rf_asChar(x))
#define STRING_VALUE(x) CHAR(Rf_asChar(x))

In Rinternals.h.

See also

Examples

# Convert an R object to a C-string (char *) to_string <- inline::cfunction(c(x = "any"), ' const char* x_; x_ = CHARACTER_VALUE(x); Rprintf("%s\\n", x_); return R_NilValue; ' const char* x_; x_ = CHARACTER_VALUE(x); Rprintf("%s\\n", x_); return R_NilValue; ') invisible(to_string(1L))
#> 1
invisible(to_string(pi))
#> 3.141593
invisible(to_string(TRUE))
#> TRUE
invisible(to_string(list(a = 'b')))
#> NA