# Calling source with RLink in Mathematica

Let's imagine that I have a file called gensys.R where a function gensys is defined, which I would like to use in the mathematica environment and work with it.

REvaluate[
"source(" path\gensys.R ")"]


However, I receive an error message when I run the command, related to the double use of the " sign...

Any help would be appreciated.

• You have to escape quotation marks in a string with "\"". The same hold true for backslashes (you need "\\"). So try this: REvaluate["source(\"path\\gensys.R\")"]. – Henrik Schumacher May 29 '18 at 11:05
• @HenrikSchumacher Thanks for the comment. However, now I get Java(TM) Plataform SE binary critical error... – An old man in the sea. May 29 '18 at 11:09
• @HenrikSchumacher Is there a pdf user guide which I can learn about using RLink. The documentation on the wolfram site seems to be lacking... maybe it's some inattention on my part. – An old man in the sea. May 29 '18 at 13:34
• That's something you should ask @Szabolcs. – Henrik Schumacher May 29 '18 at 14:08
• The right one to ask would be @LeonidShifrin, as was working on this. Have you ensured, that your path is indeed correctly escaped and exists? It seems odd, that such a simple call should crash the JRE. – halirutan May 29 '18 at 14:35

REvaluate["source(\"path1/path2/gensys.R\")"]

• Windows usually supports both \  and / as a path separator. To write \  in an R string, one needs to escape it as "\\". You are writing an R string inside of a Mathematica string, which needs even more escaping. Now it would look like "\"\\\\\"". Alternatively, you can use single quotes for R strings, which would make this "'\\\\'". – Szabolcs May 29 '18 at 11:48
• I believe @Henrik is right, and the path separator depends on the OS, not on the language. The behaviour you observe is due to the need to escape in R fist, then to escape in Mathematica a second time. Of course, the most practical solution is to use / as a path separator (even on Windows) and to use single quotes for R strings. – Szabolcs May 29 '18 at 11:50
• @Szabolcs Double escaping? Oo Good point! Btw., this might be helpful if one has to this often: StringReplace[ ToString[source["path\gensys.R "], InputForm], {"[" -> "(", "]" -> ")"} ] – Henrik Schumacher May 29 '18 at 11:58