Add tex distribution to PATH for R studio - r

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

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!

Netlogo R Extension: user.properties file missing

I am trying to use the R extension in Netlogo 6.2.
I just cannot find the user.properties file anywhere.
I have Windows 7. According to instructions:
I installed Microsoft Visual C++ 2013
I configured the Windows PATH adding C:\Program Files\R\R-\bin\x64\ after a semicolon
I reinstalled Java to the latest version
I installed java packages and loaded the library in the R session that I am running in R Studio, using the following console commands: install.packages("rJava") and library(rJava)
I added the "extensions [ r ]" line at the top of the code in Netlogo
Now: I am getting Error 01 for lack of configuration of the user-properties file.
("LALC" is my username).
So I am looking for the user.properties file into
C:\Users\LALC\AppData\Roaming\NetLogo\6.2\r
and there is nothing in there!
Where is the user.properties file?
There is also nothing in the extensions folder.
I don't understand if I should create the user.properties file myself, and if yes, what should I write in it?
(FYI I am running Windows 7 on a Mac, using Bootcamp, but I don't think this should be an issue, correct?)
I believe I solved the problem.
As discussed, after all the installation steps, the user.properties file was missing in
C:\Users\username\AppData\Roaming\NetLogo\6.2\r
I found it in a completely different folder which is
C:\Program Files\NetLogo 6.2.0\app\extensions.bundled\r
I copied it from there and pasted it in
C:\Users\username\AppData\Roaming\NetLogo\6.2\r
This is not mentioned at all in the Netlogo instructions document at
https://ccl.northwestern.edu/netlogo/docs/r.html
and I think it should be clarified.
Anyway, now with the user.properties file in the correct location, after editing it with the correct location paths for r.home and jri.home in the Windows section (asking for those paths in R, as per instructions), and of course uncommenting those lines, I finally open the Netlogo file with the "extensions [ r ]" line at the beginning ... and I get no more error notifications.

Rstudio ignore the R path I manually set but use the deleted one

enter image description here
Even I export the R path to be the correct one, rstudio still use the deleted R path.
I checked my ~/.bashrc file and the deleted path is not in $PATH variable...
Ok , thanks for user 42's answer.
However, I can't find where is .Rprofile located and I've made too many changes to configuration files that it's hard to pinpoint where's the problem any more. I completely erase my disk division and reinstall ubuntu.
My system is ubuntu server so I try to install everything just as user rather than root. And specifically I install R, R-essentials using conda in the directory /usr. This time the Rstudio can find R without problem. Therefore I think Rstudio can only find R in certain directories... like /bin /usr/bin. And somehow it ignores R in other directories.

R Sweave: NO TeX installation detected

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:

How to build qpdf on Windows?

When running the checks for my R-package (via devtools::check()) I face the warning ''qpdf' is needed for checks on size reduction of PDFs. I found this question were it was suggested (if I understood the answer correctly) to run Sys.which(Sys.getenv("R_QPDF", "qpdf")) and see whether qpdf is found or not. In my case this just returns
qpdf
""
so, I think I didn't install qpdf correctly. Unfortunately it seems to be quite complicated to install qpdf on Windows. My first side question is: does it really is so painful and complicated to install qpdf for Windows or is there an easy solution?
I've followed the instructions until it is said to add C:\MinGW-w64\bin and C:\MinGW-w64\lib\mingw to the PATH variable. But then I don't find further specific instructions to install qpdf, only about how to build qpdf with different other programs. The second side question is: is my assumption correct that after I've build qpdf it is installed? But the real question is: What is the best way to build qpdf? I tried the ./config-mingw32 and ./config-mingw64 commands from the section "Building with MinGW" in my C:\MinGW\msys\1.0\bin\bash.exe but got the error messages ./config-mingw32: No such file or directory and have no idea how to fix this issue.
I'm using Windows 10, R version 3.3.2 Patched (2017-01-07 r71934) -- "Sincere Pumpkin Patch" and RStudio 1.0.136.
You basically do not need to build the file on windows. Please follow three steps below:
Download qpdf for windows from https://sourceforge.net/projects/qpdf/?source=typ_redirect
Extract files in a temp folder
Copy the contents of the bin folder to %SystemRoot%\System32
job done!
Sys.which(Sys.getenv("R_QPDF", "qpdf"))
qpdf
"C:\\WINDOWS\\SYSTEM32\\qpdf.exe"
To flesh out an answer provided elsewhere:
If you are running the 32-bit version of R, it is important that you download the 32-bit version of qpdf, which is the version linked from the SourceForge homepage. If you are running a 64-bit installation of R, you will need to do a bit of digging to locate the 64-bit version of qpdf, which is buried a little more deeply (version 10.0.1 is listed here).
Rather than copying files to C:/Windows/System32, a potentially safer option is to extracted the zipped qpdf directory to C:\Program Files. If you do this, you'll need to add C:\Program Files\qpdf-version_number\bin to your system PATH under the environment variables.
To do this within R, run Sys.setenv('PATH' = paste0('C:\Program Files\qpdf-version_numer\bin;', Sys.getenv('PATH')))
To do this in Windows, open the start menu, type "edit the system environment variables" to open the System Properties, and at the bottom of the "Advanced" tab click "Environment variables". Find the "Path" entry under "System variables" and click "Edit". Then, re-start R so it picks up the modified PATH.
One further step may be required to convince Windows that pqdf is safe to run.
Navigate to C:\Program Files\qpdf-version_numer\bin and execute qpdf.exe (by double-clicking). Windows 10 throws up a security warning, as it's an unrecognized executable file. You'll need to use the more options link to find the button to run the program. This done, Windows will recognize the file as safe to run and allow other software, including R, to use it.

Resources