Non-R code blocks not executable in Rmarkdown

Hi,
I'm having an issue with non-R code blocks in Rstudio, such that they have no control buttons at the top right of the code block and aren't executable (see bottom three code blocks in the attached image). If I execute the code blocks using the Run button at the top of the window, they just run as though they're R code and hence any non-R code returns errors. R-language blocks work fine. I've tried updating Rstudio but am still having the same issue.
Thanks in advance for any suggestions.

Sorry, but I am not sure to understand the issue.
Non R code block will execute using the correct executable provided in chunk options or found in PATH I think.
See documentation in the new Rmarkdown book:

Can you explain more precisely what is the specific issue you have ?

Or better, could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Thanks for the reply. I'm not sure how to provide a minimal example since the problem is not related to my code or data. The problem can be produced by creating a new markdown document, inserting any non-R code block (e.g., using the "Insert" button at the top of the document and selecting 'python'), then trying to execute any code within this block. I could provide the .Rmd file in the attached image if that would help, even though there's really nothing to it.

In the image I attached in my original post, you'll see that there are no control buttons (for instance, the green play button) at the top right of the python, bash and rcpp blocks, whereas the R block does have these controls. If I try to execute any non-R code within a non-R block (so for e.g., running python code within a python block) using the "Run Current Chunk" button or shortcut, the code is just run as though it is R. So for instance, in the image attached here, you'll see that running the blocks on lines 32 and 36 produces an error for the python code but not for the R code, even though both blocks are labeled as python.
Hope this is clearer.

Can you confirm what operating system, what version of R, and what version of RStudio you're running with?

Thank you for your reply.

I'm using
RStudio: Version 1.1.456
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5

I think support for reticulated python chunk in RStudio is available in V1.2, currently in preview. See RStudio IDE Tools for reticulate • reticulate. It will surely be confirmed or not by @kevinushey who better know the product (:wink:)

However, {knitr} :package: supports python without the IDE feature. If you render the Rmd, it may work as expected with python chunk executed with your default python engine.

2 Likes

Yep! Just to illustrate what cderv described, in RStudio 1.2.* there's even a dropdown menu that will let you insert different types of code chunks (including Python). As you can see, once I do so, the various "run chunk" and "settings" buttons appear in the Python chunk, just as they do in the R one:

R Markdown in RStudio 1.2

1 Like

Thanks! This solves the problem.

1 Like