36 if (RInside::instancePtr())
throw std::runtime_error(
"Can only have one TRInterface instance");
37 fR =
new RInside(argc, argv, loadRcpp, verbose, interactive);
51 std::string osname =
Eval(
"Sys.info()['sysname']");
54 if (!
gROOT->IsBatch()) {
55 if (
gEnv->GetValue(
"X11.XInitThread", 1)) {
58 Warning(
"OpenDisplay",
"system has no X11 thread support");
62 if (osname ==
"Linux") {
63 Execute(
"options(device='x11')");
65 Execute(
"options(device='quartz')");
75 if (
gR ==
this)
gR =
nullptr;
85 rc =
fR->parseEval(code.
Data(), fans);
86 }
catch (Rcpp::exception &__ex__) {
87 Error(
"Eval",
"%s", __ex__.what());
88 forward_exception_to_r(__ex__) ;
90 Error(
"Eval",
"Can execute the requested code: %s", code.
Data());
102 fR->parseEvalQ(code.
Data());
103 }
catch (Rcpp::exception &__ex__) {
104 Error(
"Execute",
"%s", __ex__.what());
105 forward_exception_to_r(__ex__) ;
107 Error(
"Execute",
"Can execute the requested code: %s", code.
Data());
121 rc =
fR->parseEval(code.
Data(), ans);
122 }
catch (Rcpp::exception &__ex__) {
123 Error(
"Eval",
"%s", __ex__.what());
124 forward_exception_to_r(__ex__) ;
126 Error(
"Eval",
"Can execute the requested code: %s", code.
Data());
137 fR->setVerbose(status);
149 fR->assign(*obj.
f,
name.Data());
165 if (std::string(
line) ==
".q")
break;
177 const Char_t *R_argv[] = {
"rootr",
"--gui=none",
"--no-save",
"--no-readline",
178 "--silent",
"--vanilla",
"--slave"};
181 gR->ProcessEventsLoop();
198bool IsValidRPackageName(
const TString &pkg)
203 const char first = pkg[0];
204 if (!((first >=
'A' && first <=
'Z') || (first >=
'a' && first <=
'z')))
206 for (
Ssiz_t i = 1; i <
n; ++i) {
207 const char c = pkg[i];
208 const Bool_t ok = (
c >=
'A' &&
c <=
'Z') || (
c >=
'a' &&
c <=
'z') || (
c >=
'0' &&
c <=
'9') ||
c ==
'.';
212 return pkg[
n - 1] !=
'.';
217bool IsValidRReposUrl(
const TString &repos)
222 const char *prefixes[] = {
"http://",
"https://",
"ftp://",
"file://"};
224 for (
const char *s : prefixes) {
232 for (
Ssiz_t i = 0; i <
n; ++i) {
233 const char c = repos[i];
234 if (
c ==
'\'' ||
c ==
'\\' ||
c ==
'`' ||
c ==
';' ||
c ==
'\n' ||
c ==
'\r')
245 if (!IsValidRPackageName(pkg)) {
246 Error(
"IsInstalled",
"Invalid R package name: %s", pkg.
Data());
249 TString cmd =
"is.element('" + pkg +
"', installed.packages()[,1])";
256 if (!IsValidRPackageName(pkg)) {
257 Error(
"Require",
"Invalid R package name: %s", pkg.
Data());
260 TString cmd =
"require('" + pkg +
"',quiet=TRUE)";
267 if (!IsValidRPackageName(pkg)) {
268 Error(
"Install",
"Invalid R package name: %s", pkg.
Data());
271 if (!IsValidRReposUrl(repos)) {
272 Error(
"Install",
"Invalid R repository URL: %s", repos.
Data());
275 TString cmd =
"install.packages('" + pkg +
"',repos='" + repos +
"',dependencies=TRUE)";
281#undef _POSIX_C_SOURCE
282#include <R_ext/eventloop.h>
292 fd = R_checkActivity(usec, 0);
293 R_runHandlers(R_InputHandlers, fd);
int Int_t
Signed integer 4 bytes (int).
int Ssiz_t
String size (currently int).
char Char_t
Character 1 byte (char).
bool Bool_t
Boolean (0=false, 1=true) (bool).
rl_completion_func_t * rl_attempted_completion_function
static Bool_t statusEventLoop
static ROOT::R::TRInterface * gR
This is a class to create DataFrames from ROOT to R.
This is a class to pass functions from ROOT to R.
ROOT R was implemented using the R Project library and the modules Rcpp and RInside.
TRInterface(const Int_t argc=0, const Char_t *argv[]=NULL, const Bool_t loadRcpp=true, const Bool_t verbose=false, const Bool_t interactive=true)
The command line arguments are by default argc=0 and argv=NULL, The verbose mode is by default disabl...
void Execute(const TString &code)
Method to eval R code.
static TRInterface & Instance()
static method to get an TRInterface instance reference
void SetVerbose(Bool_t status)
Method to set verbose mode, that produce extra output.
Bool_t IsInstalled(TString pkg)
Method to verify if a package is installed.
Bool_t Require(TString pkg)
Method to load an R's package.
Int_t Eval(const TString &code, TRObject &ans)
Method to eval R code and you get the result in a reference to TRObject.
void Interactive()
Method to get a R prompt to work interactively with tab completion support.
void ProcessEventsLoop()
Init event loop in a thread to support actions in windows from R graphics system.
Binding operator[](const TString &name)
void Assign(const T &var, const TString &name)
Template method to assign C++ variables into R environment.
static TRInterface * InstancePtr()
static method to get an TRInterface instance pointer
Bool_t Install(TString pkg, TString repos="http://cran.r-project.org")
Method to install an R's package.
This is a class to get ROOT's objects from R's objects.
void SetStatus(Bool_t status)
TRObject is a current valid object?
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
namespace associated R package for ROOT.
SEXP RComp_assignBufferSym
SEXP RComp_completeTokenSym
SEXP RComp_retrieveCompsSym
SEXP RComp_assignStartSym
SEXP RComp_assignTokenSym
SEXP RComp_getFileCompSym
char ** R_custom_completion(const char *text, int start, int end)