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

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.

Related

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.

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?

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.

compiling minimal knitr example fails

I'm working on getting knitr setup. I installed the latest version of R (2.15.1), Lyx 2.0 including the MiKTex 2.9 distribution, and RStudio 0.96.304 on a Windows 7 Enterprise box. I can get pdflatex output if I open up Lyx and simply view the tutorial, so the basic system is working. I then downloaded the minimal Rnw example saved it in my working directory as testknitr.Snw, opened that file in RStudio, and pressed the compile PDF button. The knitr output completes with a single warning about the parser package, and produces a file testknitr.tex. pdflatex.exe then runs, but fails, and the particular error in the log file seems to be
! LaTeX Error: Environment alltt undefined.
I received the same error when attempting to compile testknitr.tex using TexWorks. I created that file from inside R using knit("testknitr.Rnw") - different extension because of the default in RStudio. I did tell MikTek to update packages automatically when compiling. A bit of research on CTAN suggests that the alltt environment is part of the ltxbase package, which is installed when I look at the package manager. In fact it seems like a pretty core part of the whole thing!
OK - I was reading the comments on the minimal example page, and discovered a workaround to that problem, and that it is a known bug as of 19 hours ago. And yes, I doublechecked that RStudio is set to use knitr, not sweave. I now get a new error:
! LaTeX Error: Command \textquotesingle unavailable in encoding T1.
EDIT: OK! it turns out that error isn't fatal - there's a lovely pdf of the minimal example sitting in the working directory if one takes the time to look. Somewhat alarming that RStudio thinks compilation failed when it didn't?
The workaround, perhaps obvious to an experience LaTex-ie, is to add
\usepackage{alltt}
to the file. According to Yihui's comment this will be fixed in future versions, or now if you want to get the development version from github. I also tested #Yihui's comment above that the line
\usepackage[T1]{fontenc}
could be commented out. This fixes the 2nd issue in the question, and RStudio now treats the compilation as successful, cleaning up (some?) intermediate files and immediately previewing the pdf.

Resources