Knitting from rmd to html - r

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??

Related

Compile error of TeX in .rmd file to create .html

I made a .rmd file for a vignette containing TeX scripts for my package.
My procedure
Make a vignette as .rmdfile.
Make a .htmlfile by the R script devtools::build_vignettes() or devtools::document()
Open the resulting .html file via web browser [Chrome]
I found that the tex script is raw in web browser page, that is, it is not compiled yet.
Why does such phenomenon occur ? Now, compile goes well, but a few hours ago, it failed.
Does the following relate ?
> devtools::build_vignettes()
Building mypkgName vignettes
Warning message:
In system(paste(cmd, "-n")) : 'make' not found
Movin aaa.html, bbb.html, ccc.html, aaa.R, bbb.R, ccc.R to doc/
Copying aaa.Rmd, bbb.Rmd, ccc.Rmd to doc/
Building vignette index
Most raw LaTeX and raw HTML is just passed through Pandoc without changes. There are some exceptions: math in dollar signs (e.g. $x^2$) will be handled by MathJax, which can handle a subset of LaTeX.
Even if you're dealing with this subset, you will see what looks like raw LaTeX if MathJax can't run. This could happen if you have Javascript turned off in your web browser (maybe by NoScript), or if you can't connect to the MathJax website and haven't asked to reference a local copy of MathJax.

pandoc "styles" extension not found

I am using the pandoc styles extension for applying the custom style to the output word document using the rmarkdown.
It worked perfectly on my local machine. However, it's giving me an error styles extension not found on the r shiny pro server.
Unfortunately, I don't have a permission to make any configuration changes at the r shiny pro server.
I would like to know if there is any way to load the extension from the application like the way we install the packages from the server.R?
No, pandoc extensions are part of the pandoc binary (which is not written in R, but is a single executable file, compiled from Haskell) and cannot be loaded like R packages.
You would need to update to a newer pandoc version that does have this extension.

R Markdown: openBinaryFile: does not exist (No such file or directory)

I've developed a shiny app that allows user to download a HTML report via R Markdown. I'm trying to include custom css and images into my rmarkdown file. However, I keep getting this error message:
pandoc: Could not fetch (either css or image file)
openBinaryFile: does not exist (No such file or directory)
When I knit the .rmd file on R Studio, it is able to reference the image file or css that I want. However, when I run the Shiny app and download the html file, I get the above error message. I've even tried to put the images and css files in the same working directory as the .rmd file, but to no avail...
output:
html_document:
css: pandoc.css
(same error message as above)
Been trying to find a solution for this but can't seem to...can anyone help here?
I just had this issue as well, but for me the reason was that the RStudio project was on a shared drive, and I had opened it through the network location. The problem was resolved when I closed out of the project, and opened it back up through a mapped network drive. (If when you run getwd() your location starts with \\, this is probably what is happening to you.)
I had a similar problem. I was not using the full file path. I was using ~/path/to/file. I changed it to the full path (i.e. removed the ~/) and it worked.
I recently ran into the issue on my Windows work-computer where I simply set the .libPaths() in the Rprofile.site file. This in line with previous answers but a little more detailed.
Step 1
Check your current paths:
> .libPaths()
[1] "\\\\my_work_server.se/some_subdir$/username/Dokument/R/win-library/3.6"
[2] "C:/R/R-3.6.3/library"
Step 2
Look for the \\\, in this case it is the path "\\\\my_work_server.se/some_subdir$/username/Dokument/R/win-library/3.6". This path is most likely some already mounted home directory, in my case it is H: = "\\\\my_work_server.se/some_subdir$/username/. If you don't have a mounted directory you may want to fix this first or change the library path to another.
Step 3
So if you've installed R under C:/R/R-3.6.3/ you edit the file C:/R/R-3.6.3/etc/Rprofile.site and add:
.First <- function(){
.libPaths(c("H:/Dokument/R/win-library/3.6", "C:/R/R-3.6.3/library"))
}
Remember to change H: to where you have your mounted network directory.
Step 4
That's it, restart R and you should be able to knit your document.
The issue that I had with RStudio & the pandoc error (openBinaryFile error) was due to the file path in which the project was created and loaded.
Project File Path
When I created the project, I created it using the Universal path, which is the 2nd option in the image above. However, when I changed this to the mapped drive letter, the option above it, my pandoc error was gone.
I'm running RStudio 1.2.1335 and R version 3.4.4
I have been having a similar issue, with RStudio, rmarkdown and pandoc on a windows machine with network filestore. I followed various advice, mapped the drive to a letter and it still didn't help.
Eventually, I discovered that one of the paths in my libPaths contained the network location/Universal path. I updated that libpath to the mapped letter drive and everything seems to be going well!
I had a similar error message, but in my case the problem was that I used a # symbol in one of the chunk titles:
```{r show distribution of # of commits per month}
Which is no problem if you just run the notebook in Rstudio, but apparently confuses knitr/pandoc: when knitting, I got an error message like
pandoc: <path>/figure-html/show distribution of : openBinaryFile: does not exist (No such file or directory)`)
Removing the # from the chunk title solved the problem.
I just ran into the same message when running:
pandoc -s foo.html foo.md
Where I totally missed the -o flag as it should have been
pandoc -s -o foo.html foo.md
With the latter, everything is working like a charm.
I believe that I had the same issue. I first had tried Changing the Default Directory but every time I went to knit the RMarkdown file, I would get the same set of errors indicating that the process was still trying to access files on my Network's H drive rather that my local C drive, specifically it was looking in the rmarkdown library file on the network drive. I thought I was following the advice above, but after that did not work I tried deleting the rmarkdown folder in the network drive
eg: \\fwnew12\Home\My Documents\R\win-library\3.6\rmarkdown.
This seemed to force R to only use my local C drive (C:/Program Files/R/R-3.6.3/library) and finally successfully knit a PDF. Maybe this is not a recommended approach, but I just need something that works.

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

Can't open connection when shortcut-knitting in RStudio

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.

Resources