<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body style='font-size: 10pt'>
<p>Hi,</p>
<p>Sorry for the newbie question but I wish to access values contained in an R file (foo.r) using C++ (source code in bar.cpp). I am using R (3.0.1) via RStudio (0.98.501) under Ubuntu 13.10.</p>
<p>>>>> The content of foo.r is:</p>
<p>someNumber <<- 42<br />stooges <<- c("moe", "larry", "curly")</p>
<p> </p>
<p>>>>> The content of bar.cpp is:</p>
<p>#include <Rcpp.h><br />using namespace Rcpp;<br /><br />// [[Rcpp::export]]<br />int checkEnv() {<br />    // access the global env.<br />    Environment env = Environment::global_env();<br />    CharacterVector v = env["stooges"];<br />    Rcout << "Stooge Nb 2 is: " << v[1] << std::endl;<br />    return env["someNumber"];<br />}<br /><br />int main(){<br />  checkEnv();<br />  return 0;<br />}</p>
<p>I have run Rcpp::sourceCpp('foo.r') from within RStudio.</p>
<p>Question: How do I compile and run the C++ file from within RStudio? If I try to compile it outside RStudio using g++ bar.cpp -o bar, the header file Rcpp.h is not recognised. No doubt this has been asked before but I cannot find the answer and I would be most grateful for assistance.</p>
<p>Thanks.</p>
<div> </div>
</body></html>