I am trying to generate a pdf from .Rnw file using knitr package.
Please find the output of sessioninfo() below
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.6
loaded via a namespace (and not attached):
[1] evaluate_0.5.5 formatR_0.10 stringr_0.6.2 tools_3.1.0
I have installed knitr but am unable to compile the code in the .Rnw file.
There is a popup that is saying "No TeX installation detected. Please install TeX before compiling". However both TeX and pdfLaTeX is not installing for this version of R, a warning message comes saying that TeX or pdfLaTex is not available.
Thanks in advance.
As a convenience, the installr R package is a very convenient way to install TeX--and a bunch of other useful stuff. Just run installr::installr() and pick MikTeX (at least). (Not sure if it works for non-Windows.)
Wrapping my comment into an answer. knitr uses pdflatex to generate a pdf. pdflatex is a part of TeX/LaTeX installation, which is not an R package and cannot be installed using R terminal (at least natively, because installr can actually do this, as indicated by #Gregor).
You need TeX installation on your machine to work properly with knitr. There are several options, with Miktex for Windows or TexLive for linux.
Take a look at the minimal example shipped with knitr. It starts with \documentclass{article}, which is a typical first line of a TeX file.
As a final note, R markdown can produce HTML using pandoc instead, so it does not require TeX and may be a good alternative if you prefer not to use TeX/LaTeX.
Step 1: Download and Install MiKTeX from http://miktex.org/2.9/setup
Step 2: Run
Sys.getenv("PATH")
in R studio This command returns the path where Rstudio is trying to find pdflatex.exe In windows (64-bit) it should return C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe If pdflatex.exe is not located in this location Rstudio gives this error code 41.
Step 3: To set this path variable run:
Sys.setenv(PATH=paste(Sys.getenv("PATH"),"C:/Program Files/MiKTeX 2.9/miktex/bin/x64/",sep=";"))
Related
Consider the following:
test.rnw
\documentclass[12pt]{article}
\usepackage{natbib}
\usepackage[margin=1in]{geometry}
\begin{document}
<<setup, include = FALSE, echo = FALSE>>=
Sys.setenv(TEXINPUTS = getwd(),
BIBINPUTS = getwd(),
BSTINPUTS = getwd())
#
Some text \citet{brockwelldavis}
\newpage
\nocite{*}
\bibliographystyle{jasa}
\bibliography{test}
\end{document}
test.bib
#book{brockwelldavis,
author = {Brockwell, Peter J. and Davis, Richard A.},
year = 2016,
title = "Introduction to Time Series and Forecasting",
editor = "",
publisher = "Springer International Publishing",
address = "Switzerland"
}
jasa.bst
This file can be found at either https://github.com/merliseclyde/AAIS/blob/master/jasa.bst or https://github.com/auk12/MSc-Thesis-backup/blob/master/Bibliography/jasa.bst.
Problem Description
In RStudio, when I hit "Compile PDF" using test.rnw, I get
output file: test.tex
[1] "test.tex"
Running pdflatex.exe on test.tex...failed
Issues: 2 warnings
and from the log file:
Package natbib Warning: Citation `brockwelldavis' on page 1 undefined on input
line 58.
[1
{C:/Users/[my name]/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
No file test.bbl.
Package natbib Warning: There were undefined citations.
So, I run test.tex created from test.rnw using pdfLaTeX + MakeIndex + BibTeX in TeXworks, and test.bbl is created. Interestingly, test.pdf compiles correctly and can be viewed through TeXworks. I can clearly both the .bbl and .pdf files using Windows Explorer.
But when I hit "Compile PDF" in RStudio after compiling through TeXworks, I still get the same warning as above. Anyone have any insight as to how to fix this?
Additional Note
What's also baffling is that on my old computer, test.rnw compiles fine without having to use TeXworks as an intermediate step and on my new computer, it does not. The only difference I can think of is that perhaps my new computer has more updated versions of R and MikTeX. I also tried uninstalling and reinstalling MikTeX on my new computer and still ran into the same problem.
New Computer setup:
From R (using RStudio 1.2.5033):
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.3 tools_3.6.3
Through the Windows command prompt:
> pdftex --version
MiKTeX-pdfTeX 2.9.7338 (1.40.21) (MiKTeX 2.9.7380 64-bit)
Copyright (C) 1982 D. E. Knuth, (C) 1996-2020 Han The Thanh
TeX is a trademark of the American Mathematical Society.
using bzip2 version 1.0.6, 6-Sept-2010
compiled with curl version 7.61.1; using libcurl/7.61.1 WinSSL
compiled with expat version 2.2.6; using expat_2.2.6
compiled with jpeg version 9.3
compiled with liblzma version 50020042; using 50020042
compiled with libpng version 1.6.37; using 1.6.37
compiled with libressl version LibreSSL 2.8.2; using LibreSSL 2.8.2
compiled with MiKTeX Application Framework version 4.7348; using 4.7348
compiled with MiKTeX Core version 16.7375; using 16.7375
compiled with MiKTeX Archive Extractor version 1.6882; using 1.6882
compiled with MiKTeX Package Manager version 9.7364; using 9.7364
compiled with poppler version 0.60.1
compiled with uriparser version 0.9.2
compiled with zlib version 1.2.11; using 1.2.11
Old Computer setup:
From R (using RStudio 1.2.5001):
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.2 tools_3.6.2
Through the Windows command prompt:
> pdftex --version
MiKTeX-pdfTeX 2.9.6050 (1.40.17) (MiKTeX 2.9 64-bit)
Copyright (C) 1982 D. E. Knuth, (C) 1996-2016 Han The Thanh
TeX is a trademark of the American Mathematical Society.
compiled with zlib version 1.2.8; using 1.2.8
compiled with libpng version 1.6.24; using 1.6.24
compiled with poppler version 0.46.0
compiled with jpeg version 8.4
Both are using knitr and pdfLaTeX based on Tools > Global Options > Sweave in RStudio.
This has finally be resolved in the RStudio IDE, and the fix will appear in the patch release after RStudio 1.4, which is not available yet. Currently you have to use the daily build of RStudio: https://dailies.rstudio.com
In Tools -> Global Options, you can check the box "Use tinytex when compiling .tex files":
Then the bibliography should be compiled correctly.
I had a similar problem, on Windows. I tried to use R-studio and Miktex, but bibliographic citations were not generated. I installed TinyTex but it was in conflict with Texmaker. Solution: I installed the full Texlive. Everything working now.
RStudio (1.3.959), R (4.0.2), Texlive (2020-r55535), Texmaker 5.0.4, Windows 10 x64 single language.
I have just enough experience with R to get some things done, but not enough to actually troubleshoot a problem like this. I also would not call myself a programmer, though at some point that would be great. In case it matters, I usually use Rstudio.
I am trying to solve a problem where I have different entries for the same sample (microsatellites with different runs) that I need to condense into one line of information for each sample. I found the perfect package to solve my problem (package = genomatic). The trouble is, that I could not install it for use with the most recent version of R because it was created before version 3.0. So I downloaded version 2.15.3 and am working with the regular bare bones console.
Genomatic was not available through the install packages list, so I downloaded a zip file for Windows from here: http://www2.uaem.mx/r-mirror/web/packages/genomatic/index.html
and then followed the directions from pages 6-7 in the manual (link below) to install it from my own machine.
http://people.oregonstate.edu/~knausb/software/Genomatic_users_manual_v05.pdf
It appeared to install just fine, however when I go to load the library, I get the following error:
> library(genomatic)
Loading required package: tcltk
Loading Tcl/Tk interface ... done
Error in library(genomatic) :
package ‘genomatic’ does not have a NAMESPACE and should be re-installed
I looked through the forum, but could not find an answer for how to fix this. Here is the session info:
> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] tcltk stats graphics grDevices utils datasets methods
[8] base
Can somebody help me to make this work?
Thanks!
Liz
EDIT to add: I did try to reinstall, but ended up with the same results.
I'm not sure why you're getting this particular error, as the .zip file provided does appear to have a NAMESPACE file. Installing from source (which shouldn't require any extra installed tools, since the package has only R code, not any compiled [C++/C/FORTRAN] components) seems to help. You can either do this from the official CRAN archives:
library("devtools")
install_version("genomatic",version="0.0.7")
or from the old/frozen repository:
install.packages("genomatic",
repos="http://www2.uaem.mx/r-mirror/", type="source")
(My previous answer was wrong; there is a NAMESPACE file.)
I am having trouble running Rcpp on my PC in RStudio. Whenever I sourceCpp() a cpp file, even the Hello World file that comes with Rcpp::Rcpp.package.skeleton(), I get the warning
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]=".../anRpackage/src/../inst/include": The system cannot find the path specified
I searched Stackoverflow and it looks like some people get this warning if they don't have Depends: Rcpp in the DESCRIPTION of their package, but I am just running sourceCpp() so the DESCRIPTION file shouldn't matter (I also changed my DESCRIPTION file).
It is just a warning so the class and functions I wrote do appear in R, but RStudio frequently crashes after I use the functions in R a few times, which may or may not be related.
My session info:
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Rcpp_0.12.1 RevoUtilsMath_7.4.1 RevoUtils_7.4.1 RevoMods_7.4.1 RevoScaleR_7.4.1 lattice_0.20-30 rpart_4.1-9
loaded via a namespace (and not attached):
[1] codetools_0.2-10 foreach_1.4.2 grid_3.1.3 iterators_1.0.7 tools_3.1.3
I suppose it is possible that Revolution R is the culprit here, but I have no way of knowing. I would appreciate help, because I don't want to ignore this warning, and it's obviously not ideal for RStudio to crash repeatedly.
Kind Regards
This is still relevant today, so here's my discoveries.
Rcpp can generate interfaces to and from C++ and R.
These are generated with the help of attributes specified in source-files.
From these attributes, the call to Rcpp::compileAttributes() produces the headers. Whilst at it, this also create the folder <package directory>/inst/include. If you have specified no attributes, anywhere, then compileAttributes() does not create these directories.
In order to get rid of this warning, create the <package directory>/inst/include.
For more on attributes, see Rcpp attributes vignette.
Following this post and also this link , I tried to update my R version .
sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] installr_0.9
loaded via a namespace (and not attached):
[1] tools_2.14.0
But when I ran the code
updateR()
Error in file(con, "r") : cannot open the connection
It shows exactly the same error while running the following command :
check.for.updates.R() # tells you if there is a new version of R or not.
Error in file(con, "r") : cannot open the connection
install.R() # download and run the latest R installer
Error in file(con, "r") : cannot open the connection
How can I update my R version ?
Per https://github.com/talgalili/installr/#troubleshooting,
Try running:
setInternet2(TRUE)
That worked for me when I was getting the below error message:
Error in file(con, "r") : cannot open the connection
The URLs of the installr package are probably out of date. Just go the R website and download the latest version.
You will have to reinstall your packages manually though, which can be a pain. You can use rownames(installed.packages()) in your old R to get a list of the packages you currently have installed so that when you go to your new R you can just work down the list and install them all again.
You could even do
sprintf('install.packages(%s)', paste(shQuote(rownames(installed.packages())),collapse=','))
and then copy-paste that command into your new R to try reinstall everything you had installed on your old R. I personally prefer though to just install them as I need them, so that if I had packages I no longer use in the old R, I don't bother to reinstall them on the new R unless I need them.
Also, the above may fail simply because your current R is quite old compared to the new R so some packages may no longer be compatible.
Out of the blue my devtools package will not work. Here is what I get. I have tried numerous fixes on my Windows 8 machine. I have reinstalled Rtools, I have reinstalled devtools but I keep getting the follwoing
require(devtools)
Loading required package: devtools
Error in namespaceExport(ns, exports) :
undefined exports: iteratelist, rowSplit, whisker.escape, whisker.render
Where do I begin?
Winston Chang over on the devtools github said, "Strange, those errors involve the whisker package." So at his behest I am providing some additional information.
> packageVersion('whisker')
[1] ‘0.3.2’
> packageVersion('devtools')
[1] ‘1.3’
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
I found a solution. I deleted the whisker folder in ~My Documents\R\win-library\3.0\ and reinstalled the package. Everything worked.
Thanks to Winston Chang who made me realize that my devtools problems were coming from the whisker package which I believe devtools relies on. Thank you to #DWin who gave me the idea of chucking out a malfunctioning library and reinstalling the library.
It was when I issued library(whisker) that I realized the problem may not be with devtools at all but rather with whisker
> library(whisker)
Error in namespaceExport(ns, exports) :
undefined exports: iteratelist, rowSplit, whisker.escape, whisker.render
Error: package or namespace load failed for ‘whisker’
I can now load devtools and whisker.
It is odd. I would have thought that my packages would have been reinstalled when I uninstalled R and reinstalled it (one of the desperate steps I took when I was trying to troubleshoot). Evidently ~My Documents\R\win-library\3.0\whisker survived the uninstallation. Clearly I need to learn more about R installation and the ways in which the libraries can be setup.
My guess, in the absence of complete information and a log file for a command line installation, is that you have a corrupt .RData file. The .Rhistory file might alos be a source of corrupted data that results in incomprehensible error messages. (They are invisible to the average R user on both Windows and Mac file browsers.) Windows Explorer let's you choose to show hidden files. In WinXP one of the choices off the "Folder Options" dialog is the "View" panel. Delete first the .Rdata file and if that doesn't work then also delete the .Rhistory file.
My guess was wrong, so if RTools is available then:
install.packages("RGoogleDocs",
repos="http://www.omegahat.org/R", type="source")