|
RInside Version 0.2.10
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*- 00002 // 00003 // Simple example showing how to use R[] = ; 00004 // 00005 // Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois 00006 00007 #include <RInside.h> // for the embedded R via RInside 00008 00009 int main(int argc, char *argv[]) { 00010 00011 RInside R(argc, argv); // create an embedded R instance 00012 00013 R["x"] = 10 ; // assignment can be done directly via [] 00014 R["y"] = 20 ; 00015 00016 R.parseEvalQ("z <- x + y") ; // R statement evaluation and result 00017 int sum = R["z"]; // retrieval via access using [] and implicit wrapper 00018 std::cout << "10 + 20 = " << sum << std::endl ; 00019 00020 // we can also return the value directly 00021 sum = R.parseEval("x + y") ; 00022 std::cout << "10 + 20 = " << sum << std::endl ; 00023 00024 exit(0); 00025 } 00026