/usr/bin/texi2dvi: cannot create directory - r

After upgrading Ubuntu from 14.04 to 16.04, whenever I use
knit2pdf(input="ABC.Rnw", quiet = TRUE)
in RStudio Version 0.99.1197, I get the following error:
processing file: ./202Analysis.Rnw Error in texi2dvi(file = file, pdf
= TRUE, clean = clean, quiet = quiet, : Running 'texi2dvi' on 'ABC.tex' failed. Messages: mkdir: cannot create directory
‘Yaseen/XYZ’: No such file or directory /usr/bin/texi2dvi: cannot
create directory: Yaseen/XYZ
Edited
My directory ‘Yaseen/XYZ STU’ is containing spaces. Everything works fine after removing these spaces. However the same code was working fine with Ubuntu 14.04. How can I make this (directory names containing spaces) workable with Ubuntu 16.04?
Edited 2
This link says:
To build the PDF documentation, you will need a version of TeX Live or texinfo that includes texi2dvi (BEWARE: recent TeX Live, and some texinfo RPMs, do NOT include texi2dvi).

I agree with the previous comments in that the space in the directory seems to be the culprit.
Have you tried escaping the whitespace in your output directory?
knit2pdf(input="ABC.Rnw", quiet = TRUE, output = "Yaseen/XYZ\ STU")

Related

Can't understand the error message from blogdown

I am trying to make a blog with blogdown using my windows machine, but get this error message when I use RStudio (File/New Project/New Directory/Website using blogdown/ ... and enter Directory name: "new"):
setwd("C:/Users/AndrésLagerlöf/OneDrive - Andrés Lagerlöf Konsulttjänst AB/R/blog")
'C:\Users\Andr‚sLagerl”f\AppData\Roaming\Hugo\hugo.exe" new site "new' is not recognized as an internal or external command,
operable program or batch file.
Error in shell(cmd, mustWork = TRUE, intern = intern) :
'"C:\Users\AndrésLagerlöf\AppData\Roaming\Hugo\hugo.exe" new site "new" --force -f toml' execution failed with error code 1
I do not know what to make out of this error message. Does anyone know how to fix this?
I use R version 4.0.0 and RStudio Version 1.2.5033.
Kind regards,
Andrés
You may consider installing Hugo to a path that does not contain multibyte characters. Per documentation ?blogdown::install_hugo:
If you want to install Hugo to a custom path, you can set the global option blogdown.hugo.dir to a directory to store the Hugo executable before you call install_hugo(), e.g., options(blogdown.hugo.dir = '~/Downloads/hugo_0.20.1/').
This is also mentioned in Appendix D.1 in the blogdown book. You'd better set this option in your .Rprofile (see Section 1.4 for how), so the setting won't be lost after you restart R.

Can't move file after download and unzip

I'm trying to download a zip file from a source, unzip it and after move to another directory.
First the download:
if (!file.exists("inst/extdata/sp_resultados_universo")) {
tmp <- tempfile(fileext = ".zip")
download.file("ftp://ftp.ibge.gov.br/Censos/Censo_Demografico_2010/Resultados_do_Universo/Agregados_por_Setores_Censitarios/SP_Capital_20180416.zip", tmp, quiet = TRUE)
unzip(tmp, exdir = "inst/extdata/sp_resultados_universo", junkpaths=T)
unlink(tmp)
}
The file i want is on this directory inst/extdata/sp_resultados_universo/SP Capital/Base informa�oes setores2010 universo SP_Capital (codificação inválida)/CSV/, so when i try copy to inst/extdata/sp_resultados_universo/ i get an error
file.rename("inst/extdata/sp_resultados_universo/SP%20Capital/Base%20informa%87oes%20setores2010%20universo%20SP_Capital(condificação inválida)/CSV/Domicilio02_SP1.csv",
"inst/extdata/sp_resultados_universo/Domicilio02_SP1.csv")
Warning message:
In file.rename("inst/extdata/sp_resultados_universo/SP%20Capital/Base%20informa%87oes%20setores2010%20universo%20SP_Capital(condificação inválida)/CSV/Domicilio02_SP1.csv", :
it was not possible to rename file 'inst/extdata/sp_resultados_universo/SP%20Capital/Base%20informa%87oes%20setores2010%20universo%20SP_Capital(condificação inválida)/CSV/Domicilio02_SP1.csv'
for 'inst/extdata/sp_resultados_universo/Domicilio02_SP1.csv',
reason 'File or directory not found'
I'm translating the error message, so it could be inconsistent with english message.
I can change the directory name or move the file manually, but breaks the flow and it's not nice for reproducibility. How can i handle it inside R?
My system info:
Sys.info()
sysname
"Linux"
release
"4.9.0-6-amd64"
version
"#1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07)"
machine
"x86_64"
Many thanks in advance for any help.
when using R you can interact with the linux shell (or the windows cmd line) through a call to system() where you put the quoted command just as you would use in the shell,
for instance:
system("pwd") # prints current working directory
system("date") # prints
system("ls | grep .R") # prints a list of r scripts in the current working directory
system("mv file.txt /home/new_directory/file.txt") # moves your file to another directory

Error generating PDF with RMarkdown

I just bought a new Mac. I've cloned my git repo onto it, and ran the following, which worked fine on the old Mac:
rmarkdown::render(input = "statement.Rmd",
output_format="pdf_document",
output_file = paste(Payees$Payee[i], "identifying text", i, "2018_02", ".pdf", sep=''),
output_dir = "~/Desktop/path/to/directory")
I've installed tinytex on the new box, and I've run install_tinytex().
Here's the error I get:
tlmgr: package repository http://ctan.math.washington.edu/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
[1/1, ??:??/??:??] install: ulem [10k]
running mktexlsr ...
done running mktexlsr.
tlmgr: package log updated: /Users/steves2018air/Library/TinyTeX/texmf-var/web2c/tlmgr.log
tlmgr path add
! Package pdftex.def Error: File `DATA/ART/UFO_Logo.png' not found: using draft
setting.
Error: Failed to compile XXX_UFO_CL12018_02.tex. See XXX_UFO_CL12018_02.log for more info.
I'm sure I just need to install something. (By the way, I do use Homebrew, but I used the .pkg installer for R).
Can anyone give me a pointer? Thanks as always.
*Here's a link to the .log file referenced in the error msg: *

Set 'texi2dvi' for 'R CMD Rd2pdf'

My texi2dvi is apparently in a place where R CMD Rd2pdf doesn't expect it. Mine is at /usr/local/bin/texi2dvi, and it's being looked for at /usr/local/opt/texinfo/bin/texi2dvi:
[KenMacBook:~/git] % \R CMD Rd2pdf missing
Hmm ... looks like a package
Converting Rd files to LaTeX
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:
Error in running tools::texi2pdf()
I can work around this by running R_TEXI2DVICMD=/usr/local/bin/texi2dvi R CMD Rd2pdf, and then the docs are built correctly.
I'd like to put that setting in my .Rprofile so that things like RStudio (which won't read my .zshrc) and other random R sessions will see the setting. But neither of the following seems to have any effect in my .Rprofile:
Sys.setenv(R_TEXI2DVICMD='/usr/local/bin/texi2dvi')
options(texi2dvi='/usr/local/bin/texi2dvi')
I'm guessing .Rprofile doesn't get read by R CMD commands, is that correct? Is there an appropriate place to put my settings?
UPDATE:
Since Dirk doubts my doubting of .RProfile for affecting R CMD Rd2pdf :-), here's my evidence:
[KenMacBook:~/git] % tail -n2 ~/.Rprofile
Sys.setenv(TEXI2DVI='/no/where')
cat("End of RProfile\n")
[KenMacBook:~/git] % Rscript -e '2+2'
End of RProfile
[1] 4
[KenMacBook:~/git] % R CMD Rd2pdf missing
Hmm ... looks like a package
Converting Rd files to LaTeX
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:
Error in running tools::texi2pdf()
Notice that the file's settings are respected in a normal R session, but setting TEXI2DVI has no effect here.
That seems wrong as /usr/local/bin/texi2dvi should be in the $PATH.
I have
edd#max:~$ grep texi2dvi /etc/R/Renviron
## used for options("texi2dvi")
R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/bin/texi2dvi'}}
edd#max:~$
Note that if you want to set the TEXI2DVI environment variable, you probably have to do start before you start R -- think ~/.bash_profile
Here is an example explicitly setting TEXI2DVI:
edd#max:/tmp$ TEXI2DVI=/no/where R CMD Rd2pdf Rcpp-package.Rd
Converting Rd files to LaTeX ...
Rcpp-package.Rd
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: 1: /no/where: not found
Output:
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: 1: /no/where: not found
Output:
Error in running tools::texi2pdf()
edd#max:/tmp$
As you can see, it is respected.
Edit: Also let's not forget Renviron and Renviron.site so you have plenty of choices so set his.
Edit 2: As you seem to doubt ~/.Rprofile:
edd#max:~$ tail -1 .Rprofile
cat("End of .Rprofile\n")
edd#max:~$ Rscript -e '2+2'
End of .Rprofile
[1] 4
edd#max:~$
Had the same problem and figured out how to fix it - I think it has something to do with a previous installation of macports interfering with the path when R has been installed using brew (assuming you're on OSX).
Run the following in terminal:
defaults write com.apple.finder AppleShowAllFiles TRUE
Then go Apple > Force Quit > Finder > Relaunch. You'll now be able to see hidden files.
In your user directory there may be a file named .profile, in this file I commented out the line (i.e. put a # in front of it, as shown).
#export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Then navigate to your R.home() (get this by running R.home() in R)
R.home()
[1] "/usr/local/Cellar/r/3.2.4_1/R.framework/Resources"
And modify the following line in Renviron
R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/bin/texi2dvi'}}
This fixed it for me.
To put finder back to usual run
defaults write com.apple.finder AppleShowAllFiles FALSE
in the terminal and relaunch it.
Hope that helps.
The back-and-forth with Dirk produced some solutions, but they're pretty buried, so I summarize them here.
Diagnosis: etc/Renviron contains stale info.
My /usr/local/Cellar/r/3.2.2_1/R.framework/Versions/3.2/Resources/etc/Renviron file (installed using Homebrew) contains this line:
R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/opt/texinfo/bin/texi2dvi'}}
That's a remnant of someone (possibly me, possibly Homebrew's R package creator) who installed MacTeX in the default location, and then that path got frozen in time in the Renviron file. My texi2dvi is now at /usr/local/bin/texi2dvi, so this value needs to be overridden somehow.
1) $HOME/.Rprofile and $HOME/.Renviron won't help.
They don't take effect soon enough for R to notice them. R sets options("texi2dvi") based on the environment it sees at startup,
% tail -n2 ~/.Rprofile
Sys.setenv(TEXI2DVI='/no/where')
options(texi2dvi='/no/where/else')
% cat ~/.Renviron
TEXI2DVI=/no/where/at/all
% R CMD Rd2pdf myPackageDirectory # Still no joy
Hmm ... looks like a package
Converting Rd files to LaTeX
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
...
See "Initialization at Start of an R Session" for more info about startup files, though as shown above, the information in that document about overriding R_HOME/etc/Renviron is either incorrect or incomplete for this situation. Perhaps it should be amended in the section about R_CHECK_ENVIRON and R_BUILD_ENVIRON to also include something about R CMD RD2*, but I'm not sure whether that's what's going on, I only know this isn't a solution.
2) $HOME/.zshrc (and friends) won't help.
On OS X, your shell startup file is not consulted when you launch GUI apps. You could use defaults write or launchctl setenv to change the TEXI2DVI variable so that it's set when R launches, but you'd also have to stick it in your shell startup file for processes not started by launchd, which is icky. I also version my dotfiles, and I don't like sticking this bit of configuration in the launchctl ether where I can't easily remember it's there. But launchctl is presumably one solution to this.
3) etc/Renviron.site won't help.
This one is surprising - I expected it to work:
% cat /usr/local/Cellar/r/3.2.2_1/R.framework/Resources/etc/Renviron.site
R_TEXI2DVICMD=/usr/local/bin/texi2dvi
TEXI2DVI=/usr/local/bin/texi2dvi
% \R CMD Rd2pdf myPackageDirectory
Hmm ... looks like a package
Converting Rd files to LaTeX
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
So Renviron.site's settings aren't taking effect here. I'm getting impatient, so I didn't try to diagnose why.
3) Editing etc/Renviron as a last resort
So this finally works:
% grep TEXI2DVI /usr/local/Cellar/r/3.2.2_1/R.framework/Resources/etc/Renviron
TEXI2DVI=/usr/local/bin/texi2dvi ## Added by Ken
R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/opt/texinfo/bin/texi2dvi'}}
I don't like it much, because I'll lose those settings next time I upgrade R. And R's documentation specifically says "do not change ‘R_HOME/etc/Renviron’ itself". But at least it works.

How to identify LaTeX errors in .Rd R help files? [duplicate]

When building a package, I received the following warning:
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
I have no idea how to even begin diagnosing this. Is there a tool that tells me what .Rd file the problem is in?
I get no warnings about any of my Rd files in the checking documentation step....
Try R CMD Rd2pdf mypackage to create the manual, and possibly also set the --no-clean option to keep the temporary files. This should allow you to debug the LaTeX code triggering the error.
Though #Dirk's answer also helped me to fix the problem I would like to add a bit which might especially help recent updaters. That is, people who haven't encountered other LaTeX / R troubles after the update to 3.1.3 yet. The problem is little bit more general than just building. For me, on OS X the problem was that R CMD Rd2pdf as well as the R CMD CHECK expected texi2dvi to be in /usr/local/bin while it was in /usr/bin.
A symlink helped to fix the problem. On terminal type:
# to check whether the same issue exists for you
which texi2dvi
# if so
cd /usr/local/bin
ln -s /usr/bin/texi2dvi
Of course if the first line returns something else, you need to adapt the symlink here.
Concluding from the comments and from my own experience the problem often seems to be that some TeX fonts are missing, most often
inconsolata.sty and
upquote.sty
First you have to find the right directory where TeX fonts are stored - in my case this is:
C:\Program Files\R\R-3.3.0\share\texmf\tex\latex
Then you can download them here:
https://www.ctan.org/tex-archive/fonts/inconsolata/?lang=en
https://www.ctan.org/tex-archive/macros/latex/contrib/upquote?lang=en
Just copy them to the respective folder and in many cases the problem will be solved (in my case too). This should work for all operating systems.
...and another reason is that you haven't installed MikTex yet.
Download MikTex from here and follow the dialog prompts to install. I found the defaults to be reasonable and worked well for me.
Try to build your R package again. It should be OK now.
In my case, I had no error when running devtools::check() nor devtools::document() but when running R CMD check mypackage_version.tar.gz I got an error:
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
* checking PDF version of manual without hyperrefs or index ... ERROR
In this question in RStudio Community they point to a problem with LATEX installation.
I have the LATEX installation suggested in R markdown cookbook: TinyTex.
I fixed the issue by running in the R console
tinytex::latexmk(file = "../mypackage.Rcheck/mypackage-manual.tex")
This command automatically updated my LATEX installation so the output file mypackage-manual.pdf was created. After this, I did not get any other error related to PDF when running R CMD check:
* checking PDF version of manual ... OK
* DONE
If you are on Ubuntu just install Tex Live by this command:
apt-get install texlive and restart Rstudo if you use it.
First, #dirk-eddelbuettel's approach in the current question identified the missing tex package (which was "makeindex" in my case).
system("R CMD Rd2pdf --no-preview --output=./documentation-peek.pdf ." )
# ... <omitted pages of output> ...
# Warning in sys2(makeindex, shQuote(idxfile)) : '"makeindex"' not found
# Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
# unable to run 'makeindex' on 'Rd2.idx'
# Error in running tools::texi2pdf()
Then #pedro-lima's answer in https://stackoverflow.com/a/69968791/1082435 worked for my specific case.
tinytex::tlmgr_install("makeindex")
Oftentimes this error occur because of Unicode characters in the package. In this cases, the error message might look like this.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
! Package inputenc Error: Unicode character (U+009D)
(inputenc) not set up for use with LaTeX.
You can find any Unicode characters in your package using tools::showNonASCIIfile(). Here's a simple way to check for these characters in your functions and documentation:
# functions
functions <- list.files(path = './R', all.files = T, recursive = T, full.names = T)
lapply(X=functions, FUN = tools::showNonASCIIfile)
# documentation
docs <- list.files(path = './man', all.files = T, recursive = T, full.names = T)
lapply(X=docs, FUN = tools::showNonASCIIfile)

Resources