compiling legacy Sweave with RStudio 0.99.902 - r

I'm having multiple problems with the “sos” vignette in the “sos” package that has been on CRAN since 2009. I recently noticed that it fails in multiple ways, and I can't figure out how to fix several of the problems. "Compile PDF" on “sos.Rnw” in RStudio with R 3.3.0 under Mac OS X 10.11.5 produced an XQuartz pop-up as follows:
>Sweave Noweb Syntax?
>>It seems you are using the Sweave-specific syntax in line(s)
>>9, 15, <snip>; you may need Sweave2knitr("sos.Rnw") to
>>convert it to knitr'.
I did the following, as it asked:
Sweave2knitr('sos.Rnw')
This produced a file 'sos-knitr.Rnw'. I opened this file in RStudio and clicked 'Compile PDF'. I got one line only:
>Loading required package: knitr"
If I got anything else, I don't know where it went.
Any suggestion on how I can get past this?
Thanks, Spencer Graves

RStudio is using knitr by default instead of sweave to generate the code. Revert this decision by doing the following:
RStudio:
Tools -> Global Options -> Sweave -> Weave Rnw files using: Sweave

Related

knitr button in rstudio

I'm a beginner to R and Rstudio. One of my first problems is that I do not have the knitr option in rstudio, despite having installed the knitr package. I have checked and I do have the last version of Rstudio. I am aware of how dumb this question is, but I can't but ask it after I tried everything. Shockingly, I have the knitr option/button at work, where Rstudio was installed in the same fashion (apparently). I'm attaching a screenshot of my rstudio. Any ideas?
You apparently don't have your file saved with a standard extension where it will auto-detect the file type from. You can save with .Rmd or whatever is appropriate. Alternatively in the bottom right of your source pane you should see "Text File" -> Go ahead and click and change that to R Markdown or R presentation or whatever is appropriate for your particular file.

Unable to get plots displayed in Rstudio graphical viewer.

When I run my code all my graphs (both ggplot2 and plot) are displayed in an external "Quartz 2 [*]" graphical viewer.
I would like them to be displayed in the R studio GUI plot area to I can better save and view my files, along with the previous versions.
Is there anyway to stop this?
I recently updated my version of R, along with the X11 and xQuartz on my mac (also up to date), and I am guessing these updates are behind it.
I have seen many forums explaining how to get rstudio to export to an external viewer (e.g. "quartz()"), but not the other way.
I have looked, but these threads have not helped:
ggplot plots in scripts do not display in Rstudio
plot panel does not produce plots Rstudio
dev.off() even when hidden hide <- dev.off() is not working either.
Any help would be great,
Thanks.
If you upgrade R without upgrading RStudio, the graphics engine may not be compatible. To fix the "Quartz 2" popout, upgrade RStudio to a newer version that supports the graphics engine in the version of R you have installed.
I had the same problem, and noticed the following output to the console:
Warning message:
R graphics engine version 15 is not supported by this version of RStudio. The Plots tab will be disabled until a newer version of RStudio is installed.
Looks like I forgot to reinstall Rstudio as well.. That sorted my problem.

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.

Syntax highlighting for Python chunks does not work

I'm trying to create notebooks in which I present the same algorithm written in R and Python. I can easily integrate the R and Python code in a Rmd file and then create a HTML output using the 'Knit HTML' button in RStudio. However the Python code is always displayed without syntax highlighting (not like in the example at https://github.com/yihui/knitr-examples/blob/master/023-engine-python.md). I have Andre Simon's highlight software installed and functioning on my computer (MacBook Pro Retina, MacOS X 10.9).
Currently, I have the following libraries installed in R: markdown 0.6.4, knitr 1.5.15, highr 0.3.1.
Any idea what could be the problem? Thanks for your help!.
That is specific to the RStudio Markdown render, which did not enable syntax highlighting for code blocks that are not R or C++. RStudio uses highlight.js, and you can use your own version of highlight.js to highlight Python code. Or use other Markdown converters such as Pandoc.

R syntax highlighting in Terminal

Can we get syntax highlighting for R in the Terminal?
I've finally found a library that meets my needs.
Now I'm much happier with my coding environment.
colorout is an R package that colorizes R output when running in a terminal emulator.The package cannot be on CRAN because it changes code already loaded by R and this is prohibited by the CRAN Repository Policy. The package replaces the functions that output results and messages to R Console, and this is necessary because we cannot colorize the output without replacing these functions. To install it, do the following in R:
install.packages("devtools")
devtools::install_github("jalvesaq/colorout")
library("colorout")
# do something
Use something like ess on emacs or RStudio for syntax highlighting for R instead of expecting it to work in the terminal.
Another option now would be to use radian instead of the default R prompt.
As hd1 indicated, this is not an R question. You're asking the OSX Terminal.app to do something it's not capable of. A quick look around Google (happy Zamboni birthday!) shows Vim syntax Highlighting for highlighting within vim , or https://superuser.com/questions/72057/terminal-emulator-with-custom-color-palette , but dunno if these will run under Darwin.
EDIT: I can't stay away from the search :-) . So check out these threads: https://superuser.com/questions/400360/syntax-highlighting-in-terminal-mac-os-x , http://forums.macrumors.com/showthread.php?t=412609 , and a recommendation to install zsh , https://apple.stackexchange.com/questions/12161/os-x-terminal-must-have-utilities

Resources