CHARACTER_VALUE: Convert a scalar R object to a C string

Description Arguments Value Declaration See Also Examples

Description

\Sexpr[results=rd, stage=render]{c3po:::badge('mfn')} \Sexpr[results=rd, stage=render]{c3po:::badge('r2c')}

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

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

In Rinternals.h.

See Also

R_CHAR, Rf_asChar

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 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;
')

invisible(to_string(1L))
invisible(to_string(pi))
invisible(to_string(TRUE))
invisible(to_string(list(a = 'b')))

ramiromagno/c3po documentation built on Jan. 5, 2021, 8:01 p.m.