R Sweave: NO TeX installation detected - r

I've tried searching on google to fix this, with very minimal helpful solutions.
I have installed, Miktex, R and R studio. I would like to use Sweave to create PDF documents in Miktex. Everytime I open my .Rnw file, it gives a warning at the top which reads "No TeX installation detected. Please install TeX before compiling"
When I look for pdflatex on my system with the command
Sys.which("pdflatex") it returns ""
Does anyone know how to fix this? ANYTHING at all at this point would be useful.

Usually Rstudio finds the correct path to your Latex installation automatically. In your case that doesn't seem to be the case. After making sure Miktex is installed correctly (have you opened it and compiled a simple file?) you can set the pdflatex path manually:
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64", sep=.Platform$path.sep))
This is the path to my pdflatex.exe file, yours might live somewhere else.
You will have to run this every time you restart RStudio. Adding the path to pdflatex.exe to your PATH variable in Windows should make this permanent but I haven't tested that. Go to System Properties, click on Environment Variables, then on Path and then Edit. Then just enter the path to your pdflatex.exe:

Related

Can I change the location of Homebrew FFTW install? R can't seem to read FFTW3.h file located in Cellar folder

I'm trying to install wholebrain by Daniel Fürth, following the instructions on the macosX install page (available here). I am running MacOS Big Sur 11.5.2, R 4.1.2, and RStudio 2021.09.1.
Unfortunately, the program is not straight-forward to install and requires significant developer tools to work correctly. I'm not a programmer and have almost no experience with coding, so I've been mucking through the instructions for two days now trying to get the install to work correctly and I'm firmly stuck on the final step.
In RS, when I run, devtools::install_github("tractatus/wholebrain", INSTALL_opts=c("--no-multiarch")) I get the following error message:
/bin/sh: pkg-config: command not found filter.cpp:9:10: fatal error: 'fftw3.h' file not found #include "fftw3.h" ^~~~~~~~~ 1 error generated. make: *** [filter.o] Error 1 ERROR: compilation failed for package ‘wholebrain’
I have been trying to figure out what this means for quite awhile now and I think I've narrowed it down to R is not reading the location of the fftw header file from where it was installed by Homebrew. (I could be totally wrong, again- not a programmer)
From what I understand, Homebrew always installs under opt/homebrew/cellar. And, in fact, in there is the compiled fftw program with the needed "fftw3.h" file. But for some reason, RStudio is not able to find and read the file in that location.
From random googling and reading of other posted issues, I think that RStudio may expect the file to be under usr/local/include. Can I just copy and paste the header file into that folder? Or will I be screwing something up if I do that? I am totally intimidated by fftw's description of manual compilation so I don't really want to attempt that. Is there a way to change where R is looking for that header file? I already set my wd to "/" so shouldn't R be able to access any folder on my computer?
I want to post an answer here for anyone who comes after me with the same issue. It came down to RStudio not recognizing the programs Homebrew had installed because it wasn't reading the file location where Homebrew saves them. Homebrew always installs programs in /opt/homebrew/... Here is what I had to do:
In RStudio, open your Renviron file using this command: usethis::edit_r_environ()
In the file that opens (which for me was totally blank), type: PATH=/opt/homebrew/bin:${PATH}, or whatever your particular path you want prepended to the Renviron path is.
Quit RStudio and, when prompted, save. Re-open RStudio and run Sys.getenv("PATH") to check. Your new path (in the example above, '/opt/homebrew/bin') should now be prepended to the list of paths that RStudio will use when looking for programs/files. For me this now looks like /opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/RStudio.app/Contents/MacOS/postback
Finally, I want to say thank you very much to Mark Setchell who really helped point me in the correct direction!

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

After running R CMD Check, the mypackage.Rcheck directory with PDF manual disappeared

I have installed Rtools v.31 and MKTeX2.9 on my laptop before building my R package. After I ran R CMD check, a directory called mypackage.Rcheck and the source file mypackage_1.x.tar.gz appeared, and while RStudio build package function is checking everything, there is no warning or error message, but at the end when it said (as follows), the corresponding mypackage.Rcheck directory which is supposed to contain the PDF manual disappeared:
checking PDF version of manual ... OK
DONE
NOTE: There were 3 notes.
See
'C:/.../package/mypackage.Rcheck/00check.log'
for details.
R CMD check succeeded
I thought it might be a version conflict between Rtools and R because I'm using R13.1.2 and Rtools v.31, where on the http://cran.r-project.org/bin/windows/Rtools/ website, it said the image isn't frozen (which I don't understand what it means). But I tried all the suggested compatible version pairs between Rtools and R, and still couldn't get it working. So I think this disappearing of mypackage.RCheck is not due to version conflict.
I don't think it's MiKTeX problem because apparently pdf is generated, but was consequently removed. I also tried using --options in R CMD check, but there is no way to force generation of pdf manual, plus pdf was generated at one point. I also read one post on this website, suggesting the use of Rutils function Rd2pdf: "R CMD Rd2pdf mypackage", but I can't run in on windows, and Rutils package is not available for R13.1.2.
can someone suggest the source of the problem or if they have seen this problem before and was able to fix it?
In RStudio: Tools -> Global Options -> Packages. There is a setting "Cleanup output after successful R CMD Check". If this is checked it removes the package.Rcheck folder after a successful check. If you uncheck this setting, the package.Rcheck folder is not removed and you will find the reference manual pdf there.
A common problem for mysterious disappearances of files from R tarballs is to accidentally specify that they should be ignored in the .Rbuildignore file. The lines in that file are regular expressions, so leaving off the anchors ^ and $ can cause them to match more files than you intended. For example,
vig.e
matches vignette.pdf (because there are no anchors to the start and end of the name, and the
dot means "any character".

Add tex distribution to PATH for R studio

I have recently begun using knitr with Rstudio. I ran into the "No tex installation detected. Please install TeX before compiling." error in both my Ubuntu and windows OS's.
After some research I was able to amend the issue in Ubuntu by adding the directory of my tex installation to PATH. I did this by including the following line in Renviron.site
PATH=/usr/local/texlive/2013/bin:${PATH}
However, the issue remains for my windows installation. I was unable to find the Renviron.site file, so I created one in the same directory of Renviron, and added the location of my tex installation in windows:
PATH=C:\texlive\2013\bin\win32:${PATH}
However this does not solve my problem and Rstudio is still unable to find my tex packages, such that
file.exists(Sys.which('texi2dvi'))
Returns FALSE.
How should I proceed?
R will always source the Rprofile.site file first. On Windows, the file is in the C:\Program Files\R\R-n.n.n\etc directory.
see here: Add TeX path to R Studio - Ubuntu and here: Customizing Startup
I found package tinytex to be of interest. It allows to install a minimal tex distrib without administrator privilege, takes care of path, and useful function to add missing tex packages. Works well with knitr
It is written by Xie Yihui author of knitr.
Let me build up to #HeavenZone's answer:
You should go onto
C:\Program Files\R\R-n.n.n\etc
directory and give permissions to modify the files in on the folder. This can be done by doing
Right click->Properties->Security->Edit->Select Users->In Permissions
list tick->Write
Once you're done you should open the file Renviron.site on the directory etc. And add a line like
PATH=C:\Program Files\MiKTeX 2.9\miktex\bin\64:${PATH}
I wrote a new line, assume that the definitions are concatenated. Perhaps you need also \pdflatex.exe in the above path.
Once you have this, restart Rstudio and it should grasp now the latex distribution.
I would probably change the title of this question to include that this is the Windows version so that it is easy to look for it, however my edit was rejected so I leave it to someone else...

Resources