1 From 71b1a935762efd24a79de193662450de5a89f67e Mon Sep 17 00:00:00 2001
2 From: Jonathan McPherson <jonathan@rstudio.com>
3 Date: Tue, 14 Jan 2020 12:53:20 -0800
4 Subject: [PATCH] use R_NoSave over R_Slave for R 4.0+
5
6 ---
7 src/cpp/r/CMakeLists.txt | 12 ++++++++++++
8 src/cpp/r/config.h.in | 8 +++++++-
9 src/cpp/r/session/REmbeddedPosix.cpp | 20 ++++++++++++++------
10 3 files changed, 33 insertions(+), 7 deletions(-)
11
12 diff --git a/src/cpp/r/CMakeLists.txt b/src/cpp/r/CMakeLists.txt
13 index 6984ae309c..29784b8b67 100644
14 --- a/src/cpp/r/CMakeLists.txt
15 +++ b/src/cpp/r/CMakeLists.txt
16 @@ -15,6 +15,18 @@
17
18 project (R)
19
20 +# find the version of R in play
21 +find_package(LibR REQUIRED)
22 +execute_process(
23 + COMMAND "${LIBR_EXECUTABLE}" "--vanilla" "--slave" "-e" "cat(as.character(getRversion()))"
24 + OUTPUT_VARIABLE LIBR_VERSION)
25 +
26 +# parse and save the R version to a variable
27 +string(REPLACE "." ";" R_VERSION_LIST "${LIBR_VERSION}")
28 +list(GET R_VERSION_LIST 0 R_VERSION_MAJOR)
29 +list(GET R_VERSION_LIST 1 R_VERSION_MINOR)
30 +list(GET R_VERSION_LIST 2 R_VERSION_PATCH)
31 +
32 # include files
33 file(GLOB_RECURSE R_HEADER_FILES "*.h*")
34
35 diff --git a/src/cpp/r/config.h.in b/src/cpp/r/config.h.in
36 index 6ba67c8e09..00bc8b6191 100644
37 --- a/src/cpp/r/config.h.in
38 +++ b/src/cpp/r/config.h.in
39 @@ -1,7 +1,7 @@
40 /*
41 * config.h.in
42 *
43 - * Copyright (C) 2009-12 by RStudio, Inc.
44 + * Copyright (C) 2009-20 by RStudio, Inc.
45 *
46 * Unless you have received this program directly from RStudio pursuant
47 * to the terms of a commercial license agreement with RStudio, then
48 @@ -16,4 +16,10 @@
49
50 #cmakedefine PANGO_CAIRO_FOUND
51
52 +// Important: These variables represent the version of R found during
53 +// compile/link time, NOT the version of R present at runtime.
54 +#define R_VERSION_MAJOR ${R_VERSION_MAJOR}
55 +#define R_VERSION_MINOR ${R_VERSION_MINOR}
56 +#define R_VERSION_PATCH ${R_VERSION_PATCH}
57 +
58
59 diff --git a/src/cpp/r/session/REmbeddedPosix.cpp b/src/cpp/r/session/REmbeddedPosix.cpp
60 index ac71b94522..73e2e2ce7f 100644
61 --- a/src/cpp/r/session/REmbeddedPosix.cpp
62 +++ b/src/cpp/r/session/REmbeddedPosix.cpp
63 @@ -1,7 +1,7 @@
64 /*
65 * REmbeddedPosix.cpp
66 *
67 - * Copyright (C) 2009-19 by RStudio, Inc.
68 + * Copyright (C) 2009-20 by RStudio, Inc.
69 *
70 * Unless you have received this program directly from RStudio pursuant
71 * to the terms of a commercial license agreement with RStudio, then
72 @@ -38,6 +38,8 @@ extern "C" void (*ptr_R_ProcessEvents)(void);
73 extern "C" typedef void (*ptr_QuartzCocoa_SetupEventLoop)(int, unsigned long);
74 #endif
75
76 +#include "config.h"
77 +
78 extern int R_running_as_main_program; // from unix/system.c
79
80 using namespace rstudio::core;
81 @@ -103,14 +105,20 @@ void runEmbeddedR(const core::FilePath& /*rHome*/, // ignored on posix
82 //
83 structRstart rp;
84 Rstart Rp = &rp;
85 - R_DefParams(Rp) ;
86 - Rp->R_Slave = FALSE ;
87 + R_DefParams(Rp);
88 +#if R_VERSION_MAJOR > 3
89 + // R 4.0 and above use --no-echo to suppress output
90 + Rp->R_NoEcho = FALSE;
91 +#else
92 + // R 3.x and below use --slave
93 + Rp->R_Slave = FALSE;
94 +#endif
95 Rp->R_Quiet = quiet ? TRUE : FALSE;
96 - Rp->R_Interactive = TRUE ;
97 - Rp->SaveAction = defaultSaveAction ;
98 + Rp->R_Interactive = TRUE;
99 + Rp->SaveAction = defaultSaveAction;
100 Rp->RestoreAction = SA_NORESTORE; // handled within initialize()
101 Rp->LoadInitFile = loadInitFile ? TRUE : FALSE;
102 - R_SetParams(Rp) ;
103 + R_SetParams(Rp);
104
105 // redirect console
106 R_Interactive = TRUE; // should have also been set by call to Rf_initialize_R
|