What is the most direct way to include R code in Sagetex? I tried %r, which does not work. (I do not want to use both Sweave and Sagetex.)


%r is a construct that only works in the Sage notebook or SageMathCloud. I suspect that the best thing here really is to use Sweave and SageTeX. You might be able to awkwardly get by with just SageTeX using Sage's R interface: for example,

sage: r.summary(r.c(1,2,3,111,2,3,2,3,2,5,4))
  Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  1.00    2.00    3.00   12.55    3.50  111.00

Doing r.foo(...) calls R's command foo (if it has been hooked into Sage). Here are some other things you can do:

sage: r.sd([1,2,3,4,100])
[1] 43.61766
sage: r.qnorm(.7123)
[1] 0.5601165

You might be able to typeset such things with the sagecommandline environment.

  • Maybe knitr would be another thing to use in this event. – kcrisman Nov 27 '15 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.