Open EmmanuelCharpentier opened 6 years ago
Addition : a start in the right direction is discussed in this ask.sagemath.org question. TL;DR : it isn't sufficient (ATM, we are able to start a Sage IPython session, which can't be restored successfully after exit
), but I have hints that it might work if we can manage to do what the IPython %load_ext sage
statement does in a Python session...
Complementary question : could the Python (Sage, in my case) object interfacing Python to the calling R session be renamed (at least for Sage sessions) from r
to, say, r_caller
? r
is used to interface with an "inferior R" called from Sage, and has some mighty ties with the rest of the system (and R
is semi-officially reserved for interaction with the R library via Rpy2). This renaming would also allow the re-use of old code without fear of name clashes...
Sagemath (a. k. a. Sage) is a mathematics software written in (and close to) Python. Its interactive environment is IPython, and it accepts grosso modo almost any legan python code (Python 2 at the moment, but support for Python3 is coming). Its REPL preprocesses inputs (for example, 2^3 is interpreted as 2**3). Of course, it extends python a lot in the math department.
Having
reticulate
support it would make R users able to use Sage symbolic and algebraic abilities. For example, a paper written withknitr
orRmarkdown
could also use Sage for symbolic calculations supporting the R code.Something like this can currently be (awkwardly) done by using both
knitr
and either Sagetex or Pythontex from a .Rnw file. Using this is a bit involved. it implies :knit
the.rnw
file to.tex
\LaTeX
the.tex
file at least oncesage
or `pythontex the relevant filesLaTeX
the.tex
file at least once.Doing this from
.Rmd
file is even more awkward : the relevant Sage chunks can be wrapped in \LaTeX-only chunks (you end the chunk with{=latex}
), and you have to manually run Sage or Pythontex and \Latex again...With a Sage-enabled
reticulate
, the normal mechanisms for knitting should suffice. Much simpler...(The only alternative I am aware of is to use
sympy
from Python. This can be done already, but entails losing a lot of Sage-specific abilities (as well as those all the subsystems Sage can use, such as Maxima, Pari, Singular (and sympy itself), or even Maple, Mathematica or Fricas).I checked that running reticulate by passing it the location of the shell script that starts Sage is not enough : one gets an interaction with the Python interpreter supporting Sage :
The Python interpreter seems to work. But this is not enough to get Sage working :
We are still in Python, no preprocessing
and the import really failed
At least, this didn't seem to cause trouble on R's side...
Thoughts ?