我在使用RInside和控制檯時遇到了問題。這些都在ubuntu 14.04上運行,使用通過CRAN的apt-get安裝的R 3.2.4。這裏是C++和R代碼:當通過RInside運行時,在abline中出現錯誤
#include <RInside.h> // for the embedded R via RInside
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
R.parseEval("source('abline.R')");
}
abline.R
bp <- data.frame(
age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)
bp.lm <- lm(systolic ~ age)
plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)
將R代碼工作正常,從控制檯,但錯誤是在程序運行時。
[email protected]:/tmp/abtest$ ./abtest
'data.frame': 10 obs. of 2 variables:
$ age : num 28 23 52 42 27 29 43 34 40 28
$ systolic: num 70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
what(): Error evaluating: source('abline.R')
Aborted (core dumped)
的if (noInt) {
是從abline的(線18在我的版本的R)源。我完全難以理解爲什麼這隻會發生在通過RInside。
任何想法?
'附加()'是一切罪惡的根源。使用'lm()'的'data ='參數。您可能還需要設置與處理圖形輸出相關的內容。最後,這不是一個Rcpp問題。 '這更像一個'RInside'問題,所以我刪除了Rcpp標籤。 – coatless