我正在尝试实现一种宏,以使用RCall@Rinclude
Julia 包在 Julia 的文件中包含编写的 R 代码,但我无法让字符串宏识别我已阅读的字符串中编码的代码:R"..."
RCode = """
sumMyArgs <- function(i, j, z) i+j+z
"""
open(f->write(f,RCode),"RScript.R","w")
macro Rinclude(fname)
quote
rCodeString = read($fname,String)
R"$rCodeString"
nothing
end
end
@Rinclude("RScript.R")
a = rcopy(R"sumMyArgs"(3,4,5)) # Error as it can't find sumMyArgs
问题是 R"..." 字符串宏不适用于$rCodeString
. 返回的对象是 aRObject{StrSxp}
而不是 a RObject{ClosSxp}
:
julia> a = R"""$(rCodeString)"""
RObject{StrSxp}
[1] "sumMyArgs <- function(i, j, z) i+j+z\n"
julia> R"""sumMyArgs3 <- function(i, j, z) i+j+z"""
RObject{ClosSxp}
function (i, j, z)
i + j + z