RCall - error when using R""" chunck of code """

114 views
Skip to first unread message

Jan Magnusson

unread,
Sep 30, 2016, 7:13:24 AM9/30/16
to julia-stats
Hi,

My actual code does something useful, but for illustration I have these three pieces of code:

test1.jl

# TEST 1

using RCall

path_fig = string("some string")

R"""
print("Test 1")
path_fig <- $path_fig
"""

test2.jl

# TEST 2

using RCall

path_fig = string("some string")

R"""
print("Test 2")
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(hydroGOF, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(labeling, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(ggplot2, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
"""

test3.jl

# TEST 3

using RCall

path_fig = string("some string")

R"""
print("Test 3")
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(hydroGOF, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(labeling, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(ggplot2, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
path_fig <- $path_fig
"""

The two first tests work fine, but the last one (combining the two first) fails giving this error message:

ERROR: LoadError: RCall.jl: unexpected string constant
 in include at boot.jl:261
 in include_from_node1 at loading.jl:320
while loading C:\TESTS\test3.jl, in expression starting on line 16

If I copy-and-paste the code (only the R part) into the REPL when using the R mode then everything works fine. Does anyone spot the problem?

I get some of these errors once in a while, and I can solve them by rearranging the code, or separating the R code in several R""" """-blocks, but it usually takes some time.

Finally, I think RCall is an extremly useful package (apart from this problem I have).

Thanks for any help :)

Jan

I am using the following julia version:

julia> versioninfo()
Julia Version 0.4.6
Commit 2e358ce (2016-06-19 17:16 UTC)
Platform Info:
  System: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Michael Krabbe Borregaard

unread,
Sep 30, 2016, 9:50:36 AM9/30/16
to julia...@googlegroups.com
Could you reduce the minimal example a bit? I am on mac, so can't use the lib.loc string, and this does not cause any errors on my system

```

 R"""
       print("Test 3")
       library(ggplot2)
       path_fig <- $path_fig
       """
```

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to julia-stats+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan Magnusson

unread,
Sep 30, 2016, 10:38:49 AM9/30/16
to julia-stats
Yes, here is a reduced example that works:

R"""
print("Test 4")
library(nlme)
path_fig <- $path_fig
"""

This minimal example has the same structure as the failing one in my last post (Test 3). Perhaps it has to do with the lib.loc path that I have to use since I don´t have admin privileges on my machine. I can only install stuff on my user account. But take a look at the sequence of tests below. It is kind of awkward and I don´t find any pattern in the behavior yet. Perhaps it is only a random issue with RCall, Julia and Windows.

path_fig = string("some string")

# WORKS

R"""
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
path_fig <- $path_fig
"""

# ADD ANOTHER LIB - WORKS

R"""
print("Test 5")
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(hydroGOF, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
path_fig <- $path_fig
"""

# ADD ANOTHER LIB - WORKS

R"""
print("Test 5")
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(hydroGOF, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(labeling, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
path_fig <- $path_fig
"""

# ADD ANOTHER LIB - DOES NOT WORK!!!

R"""
print("Test 5")
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(hydroGOF, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(labeling, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
library(ggplot2, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
path_fig <- $path_fig
"""

ERROR: RCall.jl: unexpected string constant

# ONLY USE LAST LIB - WORKS

R"""
print("Test 5")
library(ggplot2, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
path_fig <- $path_fig
"""

# USUALLY I HAVE TO BREAK THE CODE IN SEVERAL BLOCKS.
# THE ONE BELOW WORKS! BUT SOMETIMES IT TAKES QUITE SOME TIME 
# TO FIND "THE RIGHT" BLOCK STRUCTURE.

R"""
print("Test 5")
library(zoo, lib.loc="C:/Users/jmg/Documents/R/win-library/3.2")
"""

R"""

Michael Krabbe Borregaard

unread,
Sep 30, 2016, 10:52:10 AM9/30/16
to julia...@googlegroups.com
I know this is a silly workaround that does not solve the issue, but could you:
```
libpath = "C:/Users/jmg/Documents/R/win-library/3.2"
R"""
print("Test 5")
library(zoo, lib.loc=$libpath)
"""


Michael Krabbe Borregaard

unread,
Sep 30, 2016, 11:00:43 AM9/30/16
to julia...@googlegroups.com
Just for the record, I get the same issue as the reported on my mac

Jan Magnusson

unread,
Oct 3, 2016, 7:01:03 AM10/3/16
to julia-stats
Thanks a lot for you effort Michael. The workaround did not work on my machine.

I´m just curious whether these problems arise when using RCall with strings, which adds a lot of quotemarks here and there, and otherwise not. If unlucky, could they mix up with the quotemarks in the call R""" code """ or R" code "? I think this issue is not super important so it is probably not worthwhile to investing them any further. After all, my code works if splitting into several R""" code """-blocks.

Michael Krabbe Borregaard

unread,
Oct 3, 2016, 8:38:49 AM10/3/16
to julia...@googlegroups.com
It cannot be just the quotation marks - check this:

using RCall
rcopy(R"""
print(paste("this", "is", "a", "test", "of", "quotation", "marks", "with", "many", "nested", "quotations", "after", "each", "other"))
"success"
""")
Have you opened an issue at RCall?

BTW, you can specify the library folder as the windows environment variable R_LIBS_USER, obviating the need for lib.loc (https://cran.r-project.org/doc/manuals/R-admin.html#Managing-libraries)


On Mon, Oct 3, 2016 at 1:01 PM, Jan Magnusson <jan.ma...@gmail.com> wrote:
Thanks a lot for you effort Michael. The workaround did not work on my machine.

I´m just curious whether these problems arise when using RCall with strings, which adds a lot of quotemarks here and there, and otherwise not. If unlucky, could they mix up with the quotemarks in the call R""" code """ or R" code "? I think this issue is not super important so it is probably not worthwhile to investing them any further. After all, my code works if splitting into several R""" code """-blocks.

--

Simon Byrne

unread,
Oct 3, 2016, 11:09:02 AM10/3/16
to julia-stats
I'm not sure what is going on here, but please do open an issue with a minimal example.

Simon
To unsubscribe from this group and stop receiving emails from it, send an email to julia-stats...@googlegroups.com.

Jan Magnusson

unread,
Oct 4, 2016, 7:09:49 AM10/4/16
to julia-stats
Thanks. I´ll open an issue soon.

Jan
Reply all
Reply to author
Forward
0 new messages