我正在尝试将字符向量从 R 传递到 C 并通过 C 字符指针引用它。但是,我不知道要使用哪个类型转换宏。下面是一个说明我的问题的小测试。
文件 test.c:
#include <Rinternals.h>
SEXP test(SEXP chars)
{
char *s;
s = CHAR(chars);
return R_NilValue;
}
文件测试.R:
dyn.load("test.so")
chars <- c("A", "B")
.Call("test", chars)
R的输出:
> source("test.R")
Error in eval(expr, envir, enclos) :
CHAR() can only be applied to a 'CHARSXP', not a 'character'
有什么线索吗?