Can I add additional R packages to Overleaf? - r

Is there any way to add packages that knitr doesn't know? I use knitr in Overleaf, and I need to use packages "pacma", "nonlinearTseries" and "RHRV". But when I tried to install them it didn't work.
I tried do add them with library function but it get me an error massage.
library("RHRV")
Error in library("RHRV"): there is no package called ’RHRV’

Unfortunately, installing a package on Overleaf is not possible, see e.g. https://tex.stackexchange.com/questions/566054/cannot-install-r-packages-in-the-knitr-environment-overleaf
You could try to contact the team behind Overleaf and ask them politely, but they can have reasons why they cannot help you.
As Overleaf is simply a TeX distribution and compiliation, with some R thrown into it, you you could consider installing R locally. Installing a TeX distribution can be more overwhelming than installing a operating system. Luckily, for knitr, the author behind made an R-package, tinytex (https://yihui.org/tinytex/) - which does almost everything for you.

Related

Difficulty installing a package in R linux, dalton_rqi

Downloaded package from below URL.
Attempted to install using below command; response shown.
library(dalton.rqi,lib.loc='/home/X/Desktop/')
Error: package ‘dalton.rqi’ was built before R 3.0.0: please re-install it
https://my.clevelandclinic.org/departments/anesthesiology/depts/outcomes-research/risk-quantification
It appears this is a compiled package that maybe I don't have the source for? Is there a way to force install of the package? I'm unable to install using Rstudio GUI in its current form as a zip. Tried repackaging to tar.gz has Rstudio was looking for and also had a non-zero exit status error.
Any ideas?
I'm afraid this can't be achieved directly. The error message says it well: to use a package in R it needs to be built on an R version matching yours.
I can suggest two ways to move forward:
Contact the authors, ask for the R sources (it is somewhat surprising they did not make them available in the first place), and build the package yourself.
Downgrade your R version as far back as needed to match the one this pre-built package used.

Unable to install conrib.url

I'm having trouble installing the contrib.url package in my RStudio on Windows. Please note that I am using the latest version of RStudio.
I have tried different means via resources I got online and from the R online community but I keep getting this error message:
"A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages"
I noticed I need this package because I am unable to knit my .Rmd files in HTML and PDF. I was advised to install tinytex and contrib.url. I have been able to install tinytex but couldn't get a way around installing contrib.url.
contrib.url is not an R package:
any(grepl("contrib.url", available.packages()))
[1] FALSE
It is a function from the utils package, though (which comes pre-installed):
?contrib.url
It can be used to specify the package type for repository URLs.
I have been able to knit the .Rmd file now to HTML. All I needed to do was to just comment out the install.packages() function before knitting and it was successful. Thanks all for your help!

Link to vignette from readme.rda

I am building an R package. I have several vignettes that I would like to include links to in my README.Rmd.
I know that vignettes are to be built optionally when installing the package.
I do not really understand where I should start. I am in the process of building the package in R studio. I would the user to be able to see the vignette just by clicking at link in the readme on GitHub. Is this possible? How?
The following obviously does not work.
[The main vignette](vignettes/Vignette.html)
You can do this, but it might be more trouble than it's worth.
The problems are
Your package directories are different in the source on Github than they are when your package is installed in R. The link you give would be fine if you actually put Vignette.html in the vignettes directory, but when your package is installed, it will be in doc.
RStudio won't put the processed vignette in either of those locations by default if you just knit Vignette.Rmd.
You don't normally commit output files on Github.
So here's what you could do to work around this. Make the link look like
[The main vignette](doc/Vignette.html)
To make sure that file is there on Github, in RStudio create the doc directory and run
rmarkdown::render("vignettes/Vignette.Rmd", output_file="doc/Vignette.html")
You'll need to commit the output file and push it to Github, but you don't want to include it when you build the .tar.gz file, so you'll also need to add the lines
^doc$
^doc/Vignette.html$
to the .Rbuildignore file in the main package directory.
With all these changes I think your vignette will be visible on Github and also after you install the package in R.
A much simpler approach is just to tell the user to run
vignette("Vignette", package = "yourpackagename")
after installing the package, but this won't make it visible on Github.

devtools build_vignette can't find functions

If I use devtools::use_vignette("my-vignette") in my package, running devtools::build_vignette() works fine.
However, once I add a call to anything from my package, it stops working, with error could not find function "myfunc". If I add a library(mypackage) call, I get the error there is no package called 'mypackage'.
(I should note that my package checks, builds & installs perfectly cleanly [with no vignettes], and running devtools::load_all() also works fine for interactive sessions.)
I know that if I build & install my package, I can then get the vignettes built. This seems like a really inefficient and dangerous way to develop; essentially forcing me to re-build and re-install the entire package on every commit, to test that the vignette isn't breaking.
Is there another way to get the vignette to recognize the package-in-progress?
If you are using RStudio IDE (which is very helpful for package developpement), you can render your Rmd document created by devtools::use_vignette, by clicking on the Knit button. It will create a preview version of your vignette.
By the way, RStudio IDE provides you with helpful shortkeys and buttons to execute your Rmd document chunk by chunk to test if it's working.
If you are not using RStudio IDE, you could render your document without building the package by using the function rmarkdown::render.
However, in order to be working, your vignette requires your package to be loaded. So, as you said, you'll have to call library(mypackage) and so your package have to be installed.
You can install your package without the vignette in the command line with devtools::install(build_vignette = FALSE). In the RStudio IDE, the button Build & Reload is enougth to intall your package.`
Another solution for non user of Rstudio IDE is to use devtools::load_all(path to your package) in your vignette in order to simulate the installation of your package in the vignette environment. Then you can build your vignette with devtools::build vignette whithout needing to install your package before.
I should underline that vignette is build automatically when your build your package. So, when development are finish, replace in the vignette devtools::load_all by library because your package is loaded before building the vignette when you build a package.
If you look up Hadley Wickham's packages in github, you will see he includes a library(xyz) at the top of his vignette, e.g. https://github.com/tidyverse/dplyr/blob/master/vignettes/dplyr.Rmd
Then his recommended way to build vignettes works:
You can build all vignettes from the console with
*devtools::build_vignettes()*, but this is rarely useful. Instead
use devtools::build() to create a package bundle with the vignettes
included.
I believe this is what you will need to submit a package to CRAN.
It is a slow development cycle, though, so for active coding, you can insert a line with devtools::load_all() to use the knit in RStudio.
I know there is already an answer but this is how I solved the same issue when using a hand written vignette.
I'm not sure if this will work for build_vignette() but when I was having trouble knitting my vignette because of this same error, what I had to do was:
<path/to/your/Rpackage>/NAMESPACE I had to add export(myFuncName) for each function I want to use in the vignette along with useDynLib(myPackageName) once.
I had to specify a VignetteBuilder option in the <path/to/your/Rpackage>/DESCRIPTION file for me it is VignetteBuilder: knitr.

Package vignette depends on tikz/pgf

My R package vignette uses tikz/pgf graphics. The R CMD check command throws an error message on operating systems where the LaTeX package tikz/pgf is not installed. On a vanilla Ubuntu system, for example, the Ubuntu package 'pgf' must be installed for R CMD check to complete without an error message. The CRAN servers seem to have tikz/pgf installed, but I cannot make sure this is always and everywhere the case. Is there any way I can add a dependency on pgf to the DESCRIPTION file of my R package? Can I just add it to the 'Depends' field (even though it is not an R package)? I would not like to trash the diagram because the package vignette is an article that was published in the Journal of Statistical Software, and I would like to use it as a vignette without any modification.
From http://cran.r-project.org/doc/manuals/R-exts.html#The-DESCRIPTION-file :
Other dependencies (external to the R system) should be listed in the ‘SystemRequirements’ field, possibly amplified in a separate README file.
There won't be any automatic check or informative error message generated by the R installation process, but at least the information will be stored in a consistent place ...

Resources