Can't open connection when shortcut-knitting in RStudio - r

I have a CSV file I made shared publicly via Google Drive. I used bit.ly to generate a nice short URL, and I can read it into R just fine via
read.csv("http://bit.ly/1pRClOk")
(It's a pretty small dataframe, 9x17, so don't be worried about trying it out.)
I put my code in in a .Rmd document, and I can knit it just fine from the console if I run knit("csvtest.Rmd"), but if I knit using the Knit HTML button in RStudio (Ctrl-Shift-K), I get
Error in file(file, "rt"): Cannot open the connection.
In general, I much prefer to knit using the shortcut, because doing so seems to knit in it's own R session which means I can be sure I'm not accidentally referencing something in my global environment. I'd also like to distribute the .Rmd file without having to explain to people that they need to explicitly knit from the console.
Is there a way I can make make the connection work when using the knit shortcuts?
I'm on Windows 7 and using current versions of RStudio (0.98.1091) and knitr (1.8).
MWE
Using this document saved as csvtest.Rmd. I can run the code in RStudio line by line, no problem, typing knit2html("csvtest.Rmd") produces an HTML document with the data. Knitting via shortcut produces the error above.
---
title: "Can knitr open connections?"
output: html_document
---
```{r}
reentry = read.csv("http://bit.ly/1pRClOk")
head(reentry)
```

If you only care about a solution under Windows, I believe you need to setInternet2(TRUE) in te Rmd file before you read the file, since it is essentially an HTTPS link, which you cannot read into R by default.
A more portable solution is to use the downloader package to download the file (you can download it to a tempfile()) before reading it.

Related

How to Prevent R from trying to open a file while knitting the document

I am trying to knit a Notebook in RStudio but am running into an issue with a very large zipped file. I do not want R to read or open the file when I knit the document. Every time I go to knit the document an error pops up saying 'No such file or directory.' The file path is correct but I am trying to work around this import.
I have tried using the following code to prevent R from running this code, but am still running into the same problem.
{r import-data, cache=FALSE}
{r, eval=FALSE}

tinytex not finding tabu.sty when downloading PDF for the first time

I am generating a PDF r markdown document as part of a downloadable report in a shiny application using download handler. I am using the tinytex package.
Once published to RStudio Connect though if I try and download I am getting an error that states that tabu.sty cannot be found and it errors. If though I then download again straight after the PDF is published and downloaded without any issues. Any thoughts as to why this may be happening? The same thing occurs in rstudio but with a different sty file (multirow.sty). I use neither tabu or multirow in my markdown documents.

Knitting from rmd to html

I'm trying to knit this rmd file for my class and I have to do it on the class server. Problem is I access to that server with a ssh connection (since I didn't want to install a virtual machine) and therefore can't use the RStudio really handy knit button
I've tried using knitr() and rmarkdown::render() and nothing seems to work.
So far i've tried :
require(knitr)
require(rmarkdown)
knit(file.rmd, file.md)
makdownToHTML(file.md, file.html)
this allows me to knit the file, but won't add the theme, author name, date and toc that are necessary for this project
I've also tried :
rmarkdown::render(file.rmd)
Which gives me:
pandoc version 1.12.3 or higher is required and was not found.
I've checked and for some reason the rmarkdown::pandoc_version() is null on the server (even though it's supposed to be installed with RStudio that the rest of the class uses on the virtual machine)
Right now I am looking for way to bypass the pandoc or load the files in my home to be able to knit this rmd file once and for all...
Any idea on the matter??

R Markdown Saved on Dropbox won't compile

I am trying to compile the basic example R markdown beamer presentation (I also tried compiling the pdf and the html, neither of which worked).
It works flawlessly when I save the markdown file on my local mac book air. But when I save the file on my dropbox, I get the following error:
Loading required namespace: ffbase
Error in .First() : could not find function "load.ffdf"
Execution halted
The example file does not call ffbase in any way. I think the problem has something to do with accessing my rprofile, but I can't figure out why that would be an issue.
How do I get the markdown file to knit the pdf/html/beamer when the script is saved on dropbox?

knitr doesn't print plots in latex document [duplicate]

i have a knitr based Rnw file that is compiling to pdf perfectly fine in RStudio on mac (v0.97.316) and knitr (v1.1) but in a windows enviornment (same versions) i get a compilation error. I've checked the options in RStudio in both environments and they are consistent.
It appears that the windows setup is always injecting: "\SweaveOpts{concordance=TRUE}" into the ".tex" file even though i have no such flag in the Rnw file, and/or if i toggle the settings in the preferences, and/or if i add the "opts_knit$set(concordance=FALSE)" options to a knitr settings chunk. If i drop the line from the ".tex" file and compile it manually at the cmd prompt the output is generated as expected.
I'm not sure if this is an RStudio or knitr problem, but any pointers would be appreciated.
Note, i've also posted this question on the RStudio support board (http://support.rstudio.org/help/discussions/problems/5039-knitr-compile-problems-with-rstudio-windows?unresolve=true).
The reason that it was injecting \SweaveOpts{concordance=TRUE} is likely to be your weaver was Sweave instead of knitr, and you also enabled Rnw concordance: http://www.rstudio.com/ide/docs/authoring/rnw_weave But I cannot say for sure it is not a bug for the Windows version of RStudio. Anyway, it is easy to verify if it is an RStudio problem -- open the Compile PDF panel and you should see the log like this:
If your weaver was Sweave, you will see something like this instead:
This is my configuration (I'm under Ubuntu):
If you are using knitr indeed, and RStudio still inserts \SweaveOpts{concordance=TRUE}, I guess it must be a bug of RStudio.
I encountered this problem with "R CMD build KFAS-master" downloaded 2016-04-24 as "KFAS-master.zip" clicking "Download ZIP" from KFAS on GitHub (https://github.com/helske/KFAS). I'm unable to replicate the problem, but the work around I used was to find the line mentioned in the pop-up (copied below), and comment it out by preceding it with "%%".
After downloading it, I unzipped it and changed the name of the folder to "KFAS". Then I got a command prompt and navigated to the directory containing the KFAS-master folder renamed as KFAS. This time "R CMD build KFAS" worked as expected. Then I opened ~KFAS/vignettes/KFAS.Rmw in RStudio 0.99.893, the current version as of 2016-04-26. I changed something and saved the result. When I repeated "R CMD build KFAS", I got the problem portrayed in the image below.
Jouni Helske directed me to this post. I commented out line 69 mentioned in the screen shot below by prepending "%%" to "\SweaveOpts{concordance=TRUE}". I saved the result, and "R CMD build KFAS" worked.
Something seems to occasionally insert a line like "\SweaveOpts{concordance=TRUE}" into a *.Rnw file, but I don't know what it is. I'm running R 3.2.4 on a MacBook Pro with OS X 10.11.2.
Thanks to Yihui and others for earlier posts in this thread.
screen shot showing pop-up complaining, "It seems you are using the Sweave-specific syntax in line(s) 69... ."
I had the same problem even when knitr was set for "Weave Rnw files using" by default.
I solved it by going to Tools/Global Options/Sweave and setting "Weave Rnw files using" to Sweave and pressing Ok. Then, I went back and set it back to knitr, and everything works fine now.
I guess it was indeed Rstudio bug

Resources