Problems doing citations using RStudio with natbib with a bibliography style - r

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.

Related

Trouble installing DevTools in RStudio

I'm trying to install DevTools using RStudio with my R version 4.0.5.
I install the packages in RStudio from the CRAN repository, and everything looks fine until the following comes up:
obviously processx is a dependency of DevTools. The trouble seems to start when the system tries to use the 'as' executable in RTools. It can't seem to use it but it's definitely there and in the same folder as my gcc executable:
I've already added the following values to the following environment variables:
Variable
Value
Path
C:\Program Files\R\R-4.0.5\bin;C:\rtools42\usr\bin;
BINPREF
C:\rtools42\x86_64-w64-mingw32.static.posix\bin\
R_HOME
C:\Program Files\R\R-4.0.5\library\base\R\Rprofile
R_LIBS_USER
C:\Program Files\RPackages
R_USER
C:\Program Files\R\R-4.0.5
RTOOLS42_HOME
C:\rtools42
I'm wondering what to try next?
EDIT: See below for results of GCC -v as suggested:
Edit 2: The original issue was fixed by updating my R version, but now as I try to install a package called "markdown" I'm encountering this next issue:
Edit 3: here is the output from my sessioninfo():
sessionInfo(package = NULL)
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C LC_TIME=English_United States.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sessioninfo_1.2.2
loaded via a namespace (and not attached):
[1] compiler_4.2.1 cli_3.4.1 tools_4.2.1
Here's the output from Help > About RStudio:
RStudio
2022.07.2 Build 576
© 2009-2022 RStudio, PBC
"Spotted Wakerobin" Release (e7373ef8, 2022-09-06) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36
I believe you use the wrong R and RTools combination:
Use Rtools 4.0 for any R Version below R 4.2.0 as the following page suggests:
https://cran.r-project.org/bin/windows/Rtools/

Why am I not having any problems with the lastest versions of R and Rstudio?

I am using the latest versions of R and Rstudio and I am doing my work exclusively on Rstudio. The info about my OS and R version:
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
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_4.1.0 tools_4.1.0
More detailed info about the R version:
> version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 4
minor 1.0
year 2021
month 05
day 18
svn rev 80317
language R
version.string R version 4.1.0 (2021-05-18)
nickname Camp Pontanezen
In Rstudio when I go to Help > Check for Updates I get this:
Or using versionInfo:
> library(rstudioapi)
> versionInfo()[2:4] # ignoring the `$citation` which is not necessary for this question
$mode
[1] "desktop"
$version
[1] ‘1.4.1103’
$release_name
[1] "Wax Begonia"
One of the main problems that people are having is the ggplot2 related problems. Seems like people cannot produce ggplot2 plots with the newest version of R on the newest version of Rstudio. But this works perfectly fine for me. For example:
> library(ggplot2)
> ggplot(mtcars, aes(hp, mpg)) + geom_point()
Why this would be the case? And should I be worried about my current projects crashing all of a sudden and being not reproducible with the future updates?
Also, I am not sure if I should use the Preview version of Rstudio or keep using the current one in terms of my projects being safe.
This problem seems to be specific to Linux and macOS.
In this issue and all other reports of the bug I could find, Linux or macOS are specifically referenced. But there is not official confirmation, as far as I can see.
To confirm this theory then, I tested your code on my Ubuntu and Windows 10 machines: On Linux I experience the crash described in the issue. On Windows I had no problems.
As a further note, I experience this issue with your specific example but haven't noticed it since installing R 4.1.0 last week. Why? Because I rarely work with R scripts and the issue is apparently not affecting the Console or R Markdown (knitting or running just the chunk). Both have no problem running the example.
So I believe there is no need for you to update to the preview. For people on Unix systems, it looks a bit different. If you regularly use R scripts, you should consider the preview linked in the issue or switch to R Markdown.

Unable to install Github packages in R

I need a packages witch is located on Github. And I am aware that there are multiple solutions to install the package in R.
I am trying to install the package on a Windows server. This is what I tried:
Solution 1 (which is based on the Vignette)
install.packages("devtools")
library("devtools")
devtools::install_github("bmschmidt/wordVectors")
Error: Could not find tools necessary to compile a package
In addition: Warning messages:
1: In strptime(xx, f, tz = tz): unable to identify current timezone 'C':
Please set environment variable 'TZ'
I tried many things to solve this:
Reinstalling Devtools, use the CRAN devtools version
Reinstalling R and Rstudio (installing the latest versions as admin) (Error : Could not find build tools necessary to build)
But still the same error...
So I tried a workaround to install the packages on my computer:
Solution two
Download ZIP file from (https://github.com/bmschmidt/wordVectors)
Unzip the ZIP file
But the result is an error again:
library(devtools)
install("path/to/unzipped/file")
library("wordVectors")
Error there is no packages called wordVectors.
Anyone an idea what is going on? I struggled the whole day with this issue. Help is really appreciated! Thanks!
Edit
Also Rtools is (re)installed (the latest version...)
Edit 2
As requested in the comments (#DJV):
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
Matrix products: default
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
[6] methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.2 tools_3.5.2

Knitr plot doesn't have axes when viewed in Evince (updated RStudio, R, and Texlive)

In the following MWE, my plots have no axes at all when compiled in RStudio. However, when I do knit2pdf("myfile.Rnw") and compile the resulting .tex document, everything works fine. Why? UPDATED: the problem only happens inside Ubuntu 14.04 Evince (GNOME Document Viewer 3.10.3). When opened in Okular for example, everything works.
\documentclass{article}
\begin{document}
<<>>=
plot(rnorm(100))
#
\end{document}
Rstudio Version 0.98.1028 (latest)
Output of sessionInfo() inside a R chunk
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8
[3] LC_TIME=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8
[9] LC_ADDRESS=C
[11] LC_MEASUREMENT=en_US.UTF-8
LC_NUMERIC=C
LC_COLLATE=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_NAME=C
LC_TELEPHONE=C
LC_IDENTIFICATION=C
attached base packages:
[1] stats
graphics grDevices utils
datasets
methods
other attached packages:
[1] knitr_1.6
loaded via a namespace (and not attached):
[1] evaluate_0.5.5 formatR_0.10
highr_0.3
[5] tools_3.1.1
From within knitr:
Sys.which('pdflatex'); cat(system('pdflatex --version', intern = TRUE), sep = '\n')
pdflatex
"/opt/texbin/pdflatex"
pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014)
kpathsea version 6.2.0
Copyright 2014 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.10; using libpng 1.6.10
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with xpdf version 3.03
From terminal:
anh#anh-IdeaPad-Y570:~$ which pdflatex; pdflatex --version
/opt/texbin/pdflatex
pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014)
kpathsea version 6.2.0
Copyright 2014 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.10; using libpng 1.6.10
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with xpdf version 3.03
I've fixed the issue without being able to truly understand the cause. (My apology to everyone who has spent time to help). I just installed texlive 2014 (the version I had before was texlive 2013, which is frozen at this point), and everything works fine.
I don't think it's texi2dvi, since running knit2pdf() still spits out that texi2dvi not found error despite everything working.
My RStudio version did not change either (0.98.953, with the latest version 0.98.1028).
I did not touch any options in RStudio. The only thing that was changed is upgrading texlive from 2013 to 2014.
If I don't have an important document to write right now I'd be tempted to reinstall texlive and recreate the issue.

TeX package not installing in R version 3.1.0

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=";"))

Resources