5
votes

I use R and RStudio a lot at university for homework assignments. The assignments are usually along the lines of: "Proof theorem xy and implement your solution in R".

Currently, I mainly rely on Wolframalpha and Maple for symbolic computations, but I would like to work completely in RStudio to solve such problems.

I know that R has an interface to Sympy called rSympy and that there are computer algebra systems like RYacas. However, since RStudio can execute Python scripts if they are stored in a .Py file and send them to the RStudio console, I was wondering if it is somehow possible to use Python code within knitr chunks with engine="python" and send the script to the RStudio console without having to knit the entire document?

The workflow I am looking for is the following:

  1. Have an .RMD file in RStudio with a chunk with engine="python"
  2. Import sympy and do some symbolic computations
  3. Execute the python chunk and immediately see output in RStudio console (like one can do with normal R chunks) without knitting the entire document
  4. Ideally, it would also be possible to access the python results so that I can convert them to a R formula etc.

See this link for a screenshot: https://www.dropbox.com/s/hn8azii7cji4suz/stackexchange_question.tiff?dl=0

If you know a more elegant way to do symbolic computations in R+RStudio, I am also looking forward to your answers!

Thanks a lot to everyone who is willing to help me:) This has been bugging me for quite some time now...

1
I don't have a perfect solution for you, but here is an improvement of the python engine anyway: github.com/yihui/runrYihui Xie
Thx a lot:) I will look into this package.Christoph

1 Answers

1
votes

My problem has been solved with the latest preview of RStudio Server.

Not only can you add Python chunks and have the output immediately displayed in the RStudio notebook, but there are options for bash and SQL too.

Just wrote a simple test procedure and it works like a charm.

So problem solved.