R Notebook - code chunk gets separated in preview - r

I am using R notebook to preview the file. Even though all the code is in one chunk, a line gets separated into two. Would you please tell me how I can resolve this?
As you can see all the code is in one chunk.
However, when I run this chunk, it gets separated into two.
I am not sure if it matters but here is the code I am running.
library(MASS)
par(mfrow=c(3,1))
hist(galaxies, breaks=500)
hist(galaxies, breaks=100)
hist(galaxies, breaks=50)
Also here are the versions of R and RStudio. I an new to R so I am not sure what is causing this. If you need any other information, please let me know. Thanks
R version 3.3.2 (2016-10-31)
Rstudio version 1.0.136

Related

double ~ in R interactive terminal in VSCode

I am trying to use R in VSCode. I downloaded the R extension and followed the steps specified but I keep getting an annoying issue: when I use Alt+126 to write the character '~' in the script everything is fine, but when I run the line, in the R interactive terminal it appears twice. Also, if I use Alt+126 in the R interactive terminal, '~~' appears instead of '~' (two times the character instead of once). I have no idea why this is happening, I tried to uninstall and reinstall both VSCode and R and reset the pc but nothing changed.
I hope somebody knows how to solve this, thanks in advance!

After loading R script, it returns lots of dot

I have been working on an R script for the last several weeks. When I opened this R script this morning, I found nothing but a list of dots showed in the attached figure. I tried both RStudio and R i386, and returned the same result. I also asked my colleague to open it, but he also failed even open it in the text file. The .Rhistory can not be well opened either. Could someone help me out? You can find the R script in the shared link below. Many thanks.
https://drive.google.com/file/d/1w3wbArOXjRoOXJlrrDvHxFDjwqNobjcy/view?usp=sharing

R Markdown - First Attempt - Strange Error Message

I'm trying to create an R Markdown script for the first time today in RStudio. I have an existing R script which produces lots of graphs, and I'm hoping to use Markdown to produce .pdf files containing these graphs.
I started very simple:
```{r}
10 * 10
```
When I clicked on the "knit" button I saw an error message:
I ran getOption("repos") at the console and I saw:
"https://mran.microsoft.com/snapshot/2019-02-01"
I don't know if it's relevant (I suspect it is): I'm not using standard R, I'm using Microsoft R Client 3.5.2 because I need access to the revoScaleR package.
I don't really understand what's going on here but it looks as if I'm using out of date stuff...can anyone help fix this please?
Thank you.
Ahhhh...I think I've fixed it:
options(repos = c(CRAN = "https://cran.rstudio.com"))
Hoping this doesn't have any unintended consequences! >crosses fingers<

r plot shows up only when I type in console but not in script

I ran into a very weird problem: my R code for generating a plot only works if I type it into the console but not when I ran it inside the script (with Ctrl+Enter command)... It's the same problem with all plots (regular plots or ggplots). Also I tried it on two different computers and the same thing happened. Anyone have any idea why this is happening?
One possible reason: I installed the newest version of Rstudio on both computers so it might be an issue with the version. The exact same code worked before on an older version of rstudio...Could this be it? If so, how can I fix it?
I think I figured out what the problem was: the setting in the new version of Rstudio has a default option of outputting the plots inside the Rmarkdown script (at the very end of the script). And that's why I wasn't seeing them. You could change the setting such that it outputs in the console.
Try dev.off() to reset the graphics device.
This helps with a lot of weird graphics behaviour.
Probably too late for the original poster... However, I just ran into the same problem after installing an R update. The way I fixed it was to go to preferences, R markdown, and turn off "show inline output". For me, it was just coming out at the bottom of the chunk instead of in the plot window like I wanted. Hope that helps someone!
I just ran into this problem. I mistakenly put my plot() command inside the r markdown setup chunk. I moved it to its own code chunk and it ran as expected.

R package knitr misses R chunks

I haven't been able to use the neater knitter package with the code chunks.
Basically there's only a few number of occasions in which it interprets them well, but for the most of it the chunks are not recognized as such. That is:
Running a markdown from RStudio only renders chunks before the file is saved. If the file has been saved, then it will show the code as is: no R output.
I also tried using knitr from within LyX, and this presented other problems. The simplest example knitr.lyx was rendered correctly as a pdf, but not html. Using more complicated documents, like the RJournal template showed other errors.
Rscript --verbose --no-save --no-restore
At first I thought it had to do with my Rstudio installation, but now I'm not so sure anymore.
By the way, I'm on Ubuntu 15.04 and the files that I'm using are examples from the documentation:
Rstudio > New File > Rmarkdown... renders R output only before it's saved.
knitr's manual in LyX from Github repo.
I found the answer for this.
It's very obvious and yet easy to overlook if you don't know it.
The problem was in saving the file with the wrong extension.
If you're using R code chunks you need .Rmd extension in Rstudio.
As I was starting with markdown I was using .md. Pfff.

Resources