R -- What exactly does install_github do? - r

never used R before. I need to integrate R into continuous build.
The script I got has the line
RUN Rscript -e "devtools::install_github('my-repo', auth_token = '"$Github_Token"')"
I know this command will download the entire repo, but how is the package installed? Is it looking for the .R files, or is it looking for the .rba files?
My goal is to integrate a build process with a CI. I found a way to construct these rba files through a docker container, but these will not be checked into github. I need to make sure the install doesn't require these rba files, then I can move these files somewhere else.

The function install_github installs a package the same as any other method of package installation, but automates the download from github for you. The remote repository needs to be an R package, meaning it needs to have at least an R/ directory containing R code, a DESCRIPTION file containing the package metadata, and a NAMESPACE file describing the package imports and exports.
For install_github to work, it should not inherently require that your rba files are present.
For more information on packages, I suggest reading R packages.

Related

writing an R pkg that builds an executable during installation

I am writing an R package that needs to include an executable file (“mod.exe” in Windows environments or “mod” in Unix environments). One of the R functions in the package makes a call to the system that calls the executable as follows:
system(paste("mod", …))
Since CRAN will not accept packages with binary codeand because I would like the package to be portable to both Window and Unix systems, I would like to be able to just include the C source (“.h” and “.c”) files that can be used to build the executable “mod” in the source package. Ideally, when a user installs the R package, the source files should be compiled (with a C compiler available through Rtools on Windows or through a native C compiler on Unix) to create the executable “mod” during installation. Then, ideally, the executable “mod” would be stored in the binary package so that the aforementioned R function can call “mod” directly. (The .h and .c files have already been written so I do not want to rewrite or modify them.)
I've read http://r-pkgs.had.co.nz/package.html, looked through https://cran.r-project.org/doc/manuals/r-release/R-exts.html, and tried to find packages on CRAN that have already done something like what I’ve proposed, but haven’t been successful. I I attempted to solve my problem by putting all the C source files for “mod” into a /src directory in the source package along with a working makefile in the hope that this would cause the building of “mod” when the package was built and cause it to be stored somewhere in the binary package so that the R function could call “mod”. However, this did not work and when I try to look into the binary package the only thing I can see that was created is a /libs folder containing /i386 and /x64 folders, which both contain a dynamic linked library (on Windows, “RMCSim.dll”)-- I do not know what to do with this DLL.
If I create a version of the package in which the executable “mod” is placed into a package directory called “exec”, the R function can call the “mod” function. Unfortunately, this solution (1) is not portable to both Windows and Unix environments and (2) leads to a package that cannot be accepted by CRAN.
Please respond if you have any ideas for how to approach this problem or if you know of any examples of packages that do something similar with C source code. Thanks!

R: Error in install.packages : cannot open the connection

I was trying to install the package RINDSEL but I am unable to install it and I keep getting the following error:
Error in install.packages : cannot open the connection
I downloaded the package from:
rindsel_1.0_2.zip | Integrated Breeding Platform
and loaded it from the directory. Other packages from the directory can be installed but just not this one.
Is the package corrupt or could there be any other error?
I would really be grateful for any help. Thanks in advance
Rename the zip file RinSel Software into Rindsel. That's the name specified in the discription file.
Then, you can install the package in R with the command
install.packages("C:/path/to/Rindsel.zip",repos=NULL,type="win.binary")
That works fine... at first (!!!).
Problem with the Rindsel package is. It is quite old. It was build with R 2.13.1. Therefore, if you want to load the library which would be the next step to use the package in R you will get the error:
Problems building package (Error: "package has been build before R-3.0.0")
My suggestion: Contact the authors of the package and ask them if they can either provide the source file that you can build the package by yourself or if they can bundle the Rindsel package with a newer R version.
(Or you could try to hunt down an old R version and see if you can get the thing running with an old R... However, I would not seriously suggest to do that. It would probably result in conflicting dependencies with the other required packages...)
EDIT 15-02-2018: OP asked if one can build an R package with sources that are presumeably the Rindsel source files.
Yes, basically, you could do that. You would have to make a your own description and namespace file and put the source file in the R folder than invoke the command in R to build it....
But it's not neccessary with the script files provided by the link the OP posted.
OP, just run the scripts in R! It's quite easy.
Download the zip-file and extract it on your machine.
Go to that directory. The R command would be
setwd('path/to/your/directory')
Than run the R script, e.g, the KNIndex.r. It's simple:
source('KNIndex.r')
Then the script will run and produce some output / prompts.
For future readers,
I was able to fix the error by running RStudio with administrative privileges to get the command to work.
If that does not fix it, you might wish to try
Installing "r tools" if that is not installed already. That can be downloaded from
https://cran.r-project.org/bin/windows/Rtools/
Download a relevant package that you are trying to install (e.g., tidyverse_1.3.0.zip) from https://cran.rstudio.com/
and install that from local path
It can also be installed directly from the web using install.packages("https://cran.rstudio.com/bin/windows/contrib/4.0/tidyverse_1.3.0.zip")
I had the same problem. R was not able to extract and compile the package files to the default installation directory for some system-specific reasons (not R related).
I was able to fix this by specifying the installation directory of the package lib using:
install.packages("your package", lib = 'path/to your/required/installation/directory')
You can then load the package by specifying the lib.loc option while loading it:
library('your package', lib.loc='path/to your/required/installation/directory')
A better solution:
Create a new environment variable (if you are using windows) R_LIBS_USER with the following directory path/to your/required/installation/directory.
This will change the default installation directory of the packages and make it easier to load and install them without specifying the location everytime.

Creating a package in R using RStudio

I've created a bunch of files:
init.r
auth.r
class.r
modules/status.r
modules/mgmt.r
modules/core.r
modules/mcf.r
The source of the init.r file is:
# initiation of package
# include libraries
library(RCurl);
library(rjson);
# include files
source('auth.r');
source('class.r');
# extend class
source('modules/status.r');
source('modules/mgmt.r');
source('modules/core.r');
source('modules/mcf.r');
How do I go about creating a package out of this? The init.r file obviously needs to be initiated first.
Start with following the steps in this video:
Build an R Package in under 2 minutes with RStudio
Then read more about RStudio's Package Development feature, and also Hadley Wickam's Package basics.
See Writing R Extensions for the process of making a package. You might want to use package.skeleton to get started.
But essentially,
get rid of your init.r file,
put all your other .R files in the R directory
write Depends: RCurl, rjson in your DESCRIPTION file.
1. Build the prerequisites:
To build R Packages using RStudio, you should have the following prerequisites like
R,
RStudio,
Rtools,
Basic MikTex,
roxygen2 and devtools packages.
2. Create the RPackage project in RStudio and add all your R files (init.r,auth.r,class.r,modules/status.r,modules/mgmt.r,modules/core.r,modules/mcf.r) under the R folder of the project.
3. Add the documentation by editing the package description file. Build the project and now your package is ready to use.
it won't take more than 15 minutes to build a simple package.
If you wish to have step by step explanation to create a simple package, please visit this blog.
https://veeramaninatarajanmca.wordpress.com/2017/02/10/how-to-create-a-simple-package-in-r-using-rstudio/

Where to put package vignettes for CRAN submission?

From the Writing R Extensions Manual, I read that
As from R 2.14.0 the preferred location for the Sweave sources is the
subdirectory vignettes of the source packages, but for compatibility
with earlier versions of R, vignette sources will be looked for in
inst/doc if vignettes does not exist.
However, when I create a vignettes subdirectory of the package source, when I run devtools::check() or R CMD check I get a warning for Package vignette(s) without corresponding PDF. If I put the vignette (.Rnw and .pdf) in inst/doc the check completes without complaints. I tried looking in my library at installed packaged and did not see any directories named vignettes. Should I still use the deprecated location?
You put the .Rnw sources in vignettes/ as you did, but you missed out a critical step; don't check the source tree. The expected workflow is to build the source tarball and then check that tarball. Building the tarball will create the vignette PDF.
R CMD build ../foo/pkg
R CMD check ./pkg-0.4.tar.gz
for example will build a source package tarball from the sources in ../foo/pkg creating the .tar.gz package in the current directory with the package name and version appended. Then you run R CMD check on that source package.
If you want your vignette built for you put it in vignettes/ and build the source package. At some future date, R Core may remove the ability to build vignettes from inst/doc so go with the advised location now and avoid check the sources directly.
I had a hard time interpreting this too.
I believe the intention is that you should put the .Rnw file in vignettes/ and the PDF (suitably compacted) in inst/doc/, which technically agrees with the documentation if you read carefully enough. (That is, it says the sources should go in vignettes/. I don't see where it says in so many words that you ought to put the corresponding PDF in inst/doc/, but it doesn't not say it, and that interpretation seems to make R CMD check happy ...)
The resolution is in #GavinSimpson's answer (i.e. one is expected to build the tarball and then check it, rather than checking the source directory itself). (My two cents is that it might be best if R-core officially deprecated (and eventually removed) direct source checking rather than confusing all of us groundlings ...)

How do I fix a bug in an open source R package? [duplicate]

This question already has answers here:
How to edit and debug R library sources
(3 answers)
Closed 6 years ago.
I'd like to fix a package, but can't figure out how to edit it. I can download the source from R-Forge as a .tar.gz and unzip it. There is an "R" directory with the source and also a "tests" directory.
How do I include the sources in my own project to test my edits?
How do I run the tests? The tests each start with "library(blotter)". How do I make that load the library from the sources I've downloaded.
The recommended process is described in some detail in the manual 'Writing R Extensions' that came with your R installation.
There are also numerous tutorials all over the web.
No need to re-zip the source. Just load the package again from the source on your drive:
install.packages(/path/to/package, repos = NULL, type="source")
your method of doing the for loop to loop across R files will work in some situations but in others it may not. For example, if there is compiled non R code then looping across the *.R files may not work properly. So it's generally better to just install.packages() again.
BTW, if you clone a version control repo to your hard drive you generally don't get the zip file. So the same method is used to install.
What I have done is the following (IIRC) remove the old package remove.packages. Re zip your new package to a tar.gz file again (with your changed sources). Install the new package with install.packages with pkg = path to your zipped library, and repos=NULL.
When I'm doing testing on a package, I use a little bash script that looks like this:
#!/bin/bash
#build the package from source
R CMD build ../pkgdirectory/
#remove the old version and install the new one
R CMD REMOVE pkgname
R CMD INSTALL pkgname_0.7.tar.gz
Replace package name with the appropriate names. Save it as "make" and then run it whenever you finish a major edit. Then your testing scripts can use library(pkgname) just like normal.
I found that I could load all the sources to save me from the ridiculous repackaging by doing:
for (file in dir("../R", pattern="*.R", full.names=TRUE)) {
source(file)
}

Resources