How to build API documentation for an R package in RStudio? - r

I'm working on a very recent Windows 10 build, RStudio 1.3.959 and I've just installed the latest MikTex.
I'm trying to put together an R package using RStudio. I can build the package and the Function documentation comments are being converted into /man/*.Rd files. These are then successfully displayed when one executes ?function_name in the RStudio console window.
Unfortunately, I'm having very little luck building the PDF package API documentation (not to be mistaken as the vignette; which I can build). I've looked over a good few tutorials but they all stop short of instructing how one builds the final PDF API document that one expects with every R package.
I've tried:
Build[Windows]->More->Document ... which execute devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette'))
Build[Windows]->More->Build Source Package ... which executes devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette')) followed by devtools::build(binary = TRUE, args = c('--preclean'))
Build[Windows]->More->Build Binary Package ... which executes devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette')) followed by devtools::build(binary = TRUE, args = c('--preclean'))
All three function as expected but still no final package manual pdf file.
Doing some digging on Stack I noticed someone used the command:
devtools::build_manual()
I'm convinced this is what I need. However, when I execute that line of code I get the error:
Converting Rd files to LaTeX ...
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'
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()
Error: Failed to build manual
Which has left me none the wiser, although it's quite clear that something's a bit upset by the absence of makeindex. Help is much appreciated.

If I understand correctly, you mean the standard reference manual. For example ggplot2 reference manual. In my experience, this is thrown together by CRAN when you submit. All the manual is (as far as I can tell) a collection of things that a well documented package should have, such as a DESCRIPTION file, a NAMESPACE file, and the various .RD files for actual documentation.
Even when looking at the public github for ggplot2 we see that they do not have the manual in their repository. Additionally, there isn't any evidence in their .git*ignore files to suggest they made the manual themselves.
However, if you want to make this yourself devtools::build_manual() is the correct function call.
I was able to make the manual with a preexisting package on github. I would suggest trying to reinstall your devtools package and make sure there are no warnings or errors. It may be helpful to run a session as administrator to insure things get installed correctly.
Good luck!
I am using R version 3.4 with RStudio 1.1.453 on MacOS High Serra.

Related

Use uninstalled packages

I'm working in a package (and I'll include more later), and I'm doing a lot of changes and using it, and I'm looking for a method to can load the library without compile it, the lib is written in R.
I think the next structure:
Code
libs/
test_pkg1/
test_pkg2/
more code.R
Where the test_pkg are the dirs with the packages, they are already in the pkg format for R, the wd is set inside "Code", and then add "libs" to the library path in R, but R does not detect it.
I'm trying to use the libs in this both ways:
test_pkg1::func()
test_pkg2::func()
library(test_pkg1)
library(test_pkg2)
for the library, I can use devtools::load_all(path), and works great, but I don't want to mix the env with other funcs, so I need the other way too.
I'm not trying to use both at the same time, but I need both, the most important for this is the :: method.
I tested the libPath from here:
Change R default library path using .libPaths in Rprofile.site fails to work
But I can't do it works...., using that I get the next result:
.libPaths( c( .libPaths(), "./libs") )
test_pkg1::func()
Error in namespaceExport(ns, exports) : undefined exports: func()
Although: Warning message:
In loadNamespace(name) : package ‘test_pkg1’ has no 'package.rds' in Meta/
Note, If I install the package, all works fine, the NAMESPACE file, contains the export functions, in any case, any error there and I should not be able to install and use the libs.
Thx.
Tests from comments:
Try library(pkg, lib.loc)
library("test_pkg1", lib.loc="./libs", verbose=TRUE)
Error in library("test_pkg1", lib.loc = "./libs", verbose = TRUE) :
‘test_pkg1’ is not a valid installed package
Notice, the message is not, there is no package called, the package is detected, but seems, how is not built, I can't load it from library. I try build the package, but don't works either.
Try devtools::dev_mode(on = NULL, path = "libs")
Sadly, this method seems to have the same behavior as the .libsPath method.

Julia - how to update WinRPM in julia version 0.6.4

I'm new to Julia and I want to use COBRA Package.
For adding COBRA I use command :
Pkg.add("COBRA")
But when running, I get these errors:
INFO: Building WinRPM
WARNING: skipping repodata/repomd.xml, not in cache -- call WinRPM.update() to download
WARNING: skipping repodata/repomd.xml, not in cache -- call WinRPM.update() to download
INFO: Downloading https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Leap_42.2/repodata/repomd.xml
WARNING: Unknown download failure, error code: 2148270086
WARNING: Retry 1/5 downloading: https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Leap_42.2/repodata/repomd.xml
until:
WARNING: Unknown download failure, error code: 2148270086
WARNING: Retry 5/5 downloading: https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Leap_42.2/repodata/repomd.xml
WARNING: received error 0 while downloading
https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Leap_42.2/repodata/repomd.xml
After these errors, I have checked the link and I've found out the source is not there, anymore.
So then I ran this command as said above:
WinRPM.update()
But it has thrown this error:
ERROR: UndefVarError: WinRPM not defined
Please Help me to add COBRA to Julia. I'm using version 0.6.4 because Cobra does not work on the next versions.(Windows 10)
Any help would be appreciated.
The problem, as you've mentioned, is that the original sources used by the package aren't valid URLs anymore. The proper way to solve this is to open a pull request with the package to change the URLs (which I've now done here ). As a stopgap measure, here's a hacky way to work around this issue for now:
Do a Pkg.add("WinRPM"). This might trigger the same warnings as above, ignore these.
Next, using WinRPM to load the package we added
Now, the source URLs are read from the sources.list file (linked above) into a global WinRPM.sources variable. We're going to edit this variable's contents to point to new working URLs. (This is generally a terrible idea, to directly poke into the internals of a module and change things.)
julia> WinRPM.sources[:] = replace.(WinRPM.sources, "Leap_42.3" => "Leap_15.3")
2-element Vector{String}:
"https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Leap_15.3"
"https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win64/openSUSE_Leap_15.3"
A WinRPM.update() should now work, and download things into a local cache.
I'm using version 0.6.4 because Cobra does not work on the next versions.
I hope you mean Julia 1.6.4 here, or version 0.6.4 of something else in the stack. If you mean Julia version 0.6.4, you might face further problems down the road and find it hard to get support for such an old version.

install.packages function does not recognize new library path in RStudio

I am connecting remotely to a work server and need to be able to install R packages via RStudio. I have read through other questions/answers on this topic, but haven't been able to solve this for myself. I think the following input and output shows my issues the best: (edit: I do not have admin powers, but can call IT as last resort)
>.libPaths("C:/RWorkSpace") #setting new file path
>.libpaths() #testing
[1] "C:/RWorkSpace" "C:/Program Files/R/R-3.4.1/library"
>install.packages("bibliometrix", dependencies = TRUE, lib="C:/RWorkSpace")
The downloaded source packages are in
‘C:\Users\cortiz\AppData\Local\Temp\7\RtmpOsVuTB\downloaded_packages’
>library(bibliometrix)
Error in library(bibliometrix) : There is no package called 'bibliometrix'
>installed.packages()["bibliometrix","C:/RWorkSpace"]
Error in installed.packages()["bibliometrix","C:/RWorkSpace"] : subscript out of bounds
I just need to download the package and dependencies, and I expected them to be downloaded to the folder I specified ("C:/RWorkSpace").
very new to working with R in general so please bear with me. Any help greatly appreciated!

How to apply Spark configuration settings from R markdown document parameters

this is my first post so please be kind to me and my poor English.
I'm interested in running this code (this is just the script). It seems that running the code without customizing it is not possible but I don't understand what I should change.
Maybe I just installed Spark badly? I'm using the latest version of RStudio, this text says this but I don't understand if the latest version is suitable.
Please note that sparklyr version 0.7.0+ (available on GitHub, but not
yet released on CRAN) is needed.
I can tell you that the error occurs when it arrives in this line of code.
# Apply Spark configuration settings from R markdown document parameters
spark_param_names <- grep("spark.", names(params),
fixed = TRUE, value = TRUE)
the error is the following
Error in shell_connection(master = master, spark_home = spark_home, app_name = app_name, :
Failed to connect to Spark (SPARK_HOME is not set).
I'm a student and I'm not very experienced thanks for your patience

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