R Markdown not showing execute button for other engines - r

In R Markdown if I have a chunk coded with the normal r chunk wrappers,
```{r}
[R code]
```
A play button will appear. However, when I run a chunk wrapped like so for other language engines:
```{python}
[python code]
```
or replacing python replaced with bash/sh, I don't get a play button on the right.
Is there a package I need to install? I restarted Rstudio, and even downloaded the Lesson 5: https://rmarkdown.rstudio.com/lesson-5.html , which even shows those play buttons, and I still don't get it. I am on a mac, and saw that someone on a Windows computer was able to see the play buttons.

I think you need to install the package "knitr". Try to check that first.
Second, you might need to state explitly where your interpreter for Python is, for instance. Use
{python, engine.path = '/usr/bin/python3'}
YOUR CODE
to see if it works.

Related

Shortcut control enter does not work in R script

ctrl+R no longer works for executing script lines.
This is not a hardware/keyboard problem.
I have also restarted my PC.
I have tried on a different PC.
I have recently switched from using R to using RStudio. I thought this may have something to do with it, so I opened and resaved the script in RStudio, to no effect.
Furthermore, I have created an R-Project folder and have copied the files, including the script in question, into it. Then I started R-Studio and opened the project.
I would like to post my sessionInfo(), but do not know how to do that without executing the command.
Keep in mind that I only use R for stats purposes. I don't know much about informatics or other types of programming etc., so please try to keep it simple for me. Thanks!
In addition to the solution offered above, in Rstudio, Ctrl + Enter does not work if the chunk is broken in .Rmd files.
For example, if you press CTRL + Enter on the following line (2+2), it won't work:
```{r}
2+2
``
The chunk should end three Backtick characters, not two.
The problem was that the script file (for some reason unkown to me) did not have the correct extension (.R). When I added that to the script file extension, it worked fine again.

Rstudio Global Changes: show chunk output in console via CLI?

How can I force RStudio (v1.1.383) to evaluate R chunks always in console (instead of inline) when working with Rmarkdown documents, using a script?
I know I can set up Output chunks in Console by clicking on it:
According to this RStudio support post I could also un-check 'Show output inline for all R Markdown document' under 'Tools -> Global Options...':
But, is there a way to do it from a command line?
The reason I ask is that, I often work on my university machines and they all restore to defaults after each reset. Each time when in class, we have to manually go thru menus.
Knowing how to do it via a console command would as useful as starting each of my classes with
rm(list=ls())
There's not currently an elegant way to do this. This preference is stored inside an internal RStudio state file, in %localappdata%\RStudio-Desktop\monitored\user-settings. If you're sufficiently motivated you can write a script which sets the rmd_chunk_output_inline preference, but it's going to be unpleasant.
One thing you can do is set the chunk output type in the YAML header, like this:
---
editor_options:
chunk_output_type: console
---
You could also use an R Markdown document template with this set up for you (maybe your script could write this out).
Finally, there's an open issue for this on RStudio's github page which you might comment on and/or vote for:
https://github.com/rstudio/rstudio/issues/1607

RStudio snippet not working

I'm utilizing a Macbook pro running "El Capitan" and RStudio is version 0.99.902. I'm writing a Rmd document. I want to utilize the snippets that RStudio has built in and create my own also. By clicking Preference => Code; I can see that "Enable code snippets" is checked. However, while trying to utilize any snippet the completion is not performed. If I typed just r I should get this block of code, but nothing hapen
snippet r
```{r ${1:label}, ${2:options}}
${0}
```
I also create a simple snippet:
snippet dthen
%>%
None of the markdown snippet seems to work. Do I'm doing something wrong or any setting has to be done?
You can invoke code snippets in Markdown in RStudio using Shift+Tab after typing the snippet, but it will not currently prompt you to expand the snippet, either with Tab or by just waiting. I thought this was a bug, but the discussion in this GitHub issue says it's intended, just still-to-be-documented.
In Tools > Global Options > Code > Editing > Edit Snippets, go to the section "Markdown" and paste your snippet there. Save, OK, apply. Type r in your Rmd document (not within in a R code chunk) and click Shift+Tab. If it still does not work, try to create a new "R markdown" file (File > New file > R markdown) and check if it works there.

Automate RStudio processed RMarkdown?

I have an RMarkdown file that I use to generate a nice HTML report.
The problem is, I want to be able to automate it so that it can run on a headless server. As such there will be nobody there to start Rstudio and press the 'knithtml' button and it seems that Rstudio is doing a LOT of additional magic like having it's own version of pandoc, running all the necessary commands, applying css styles etc.
How can I take this report and generate the same thing Rstudio is generating when I press the 'knithtml' button, but by just running an R script?
Thanks.
Try using
rmarkdown::render("/PATH/TO/YOUR.Rmd", output_file="/PATH/TO/YOUR/OUTPUT.html")
instead. This assumes you've got the rmarkdown library loaded on your headless box. It will use the system pandoc, but make sure it's 1.12 or higher.
Here's what knit2html does (via the "R Markdown" tab near "Console"):
Here's a side-by-side. Left is clicking the button, right is running the command:
I had the same issue. After a lot of brute force, I got the same result as RStudio with this command line:
"path\to\Rscript.exe" -e "rmarkdown::find_pandoc(dir='path/to/RStudio/bin/pandoc'); rmarkdown::render('file.Rmd')"

gvisMotionChart is not working in R markdown file

I need to embed gvisMotionChart into an R markdown file and find an example interactive which is really helpful. However when it comes to the googlevis plotting I keep getting this error when I press the "run code" button:
connection to openCPU failed:
error
undefined
NetworkError: A network error occurred
Can anybody figure out the solutions?
Thanks in advance.
The googleVis package creates the javascript that has to be embedded into an HTML document in order for the interactive plot to run on a webpage. You won't be able to get it to work in the console or in Rstudio for that reason. The only way to know for sure if it's working is to knit it to HTML, and then publish it to Rpubs (or anywhere else online). Once it is online it will work. Depending on your browser settings, you might be able to get it to work by opening the HTML locally, but the browser often blocks the embedded plot when opened locally.
Without seeing your actual code, I can't provide you with anything more specific than that.
EDIT: I thought I would add that several months ago I made a markdown file detailing interactive plots in R for a class. You can find it here: http://rpubs.com/crmhaske/uwloo670_Interactive_Plots
If you scroll down to the very end you'll see the example I did using gvisMotionChart. You have to make sure the place where you print the graph is in it's own chunk, and that results is asis:
```{r results='asis'}
print(p,'chart')
```

Resources