how can I install unpublished package from source code - r

A colleague of mine has just built a shiny app for 16s rRNA amplicon. for that he has built a helper package for shiny app which contains all other packages needed for the app to work for example: dada2, dplyr, plyr, DECIPHER, phangorn etc etc. He has installed it in R but now I have to change some code in that helper package to add some of the new features in the app but I can’t find a way to install that package after modifications This package does not have any tar.gz or any zip file only a folder containing R scripts.
NOTE: I am using ubuntu.

You can use e.g. remotes::install_local(path = "src") to install the R package with its source code stored in directory src.

Related

Indirectly import R libraries from Github to R

I have just built a function and planned to put it into Github. The problem is that my function uses a lot of other R packages (e.g., dplyr, tidyverse,...), leading to when people clone my package from Github to R using remotes::install_github, they will have to additionally install those packages (e.g., dplyr, tidyverse,...). I wish when they install my package, they can use my package immediately. In other words, is any way to let they be able to simultaneously install all those packages when installing my R package.
My potential solution is that I will create a separate RData file whose role is to install and call those R libraries. Does it work?

Folder in github is missing when installed as R package

I have a public R package in github.
What I did was installed that package using the below commands
install.packages("devtools")
library(devtools)
install_github("ohdsi/Aphrodite") #APHRODITE is the package name
library(Aphrodite)
But I would like to make some changes to the way the package works.
Basically, I would like to make changes to the functions.R file under R folder in github.
As I used install_github command, I already have the package downloaded to my repository.
But I don't see the functions.R under R folder in my downloaded packages folder (APHRODITE).
Can help me understand how can I find the files to make changes?
Note: My appearance settings is set to show all hidden files and folder as well.
In github I see the below whereas in the downloaded packages folder (APHRODITE), I see something different. How can I find the functions.R file to make changes to the code locally?

How do i keep source files when using R's devtools library function 'install'

I am trying to build an R package (DESeq2) from source so that I can debug it. I've installed all the dependencies required and I'm following Hillary Parker's instructions for creating R packages. I'm running this on CentOS 6.6 using R-3.4.2.
I run :
library("devtools")
install("DESeq2", keep_source=TRUE)
It installs it in the directory with all my other R libraries. When I look at the installed DESeq2 library it is missing all the DESeq2/R/*.R and DESeq2/src/*.cpp files.
QUESTION : Where are these files and why didn't they get installed? This does not seem like the expected behavior.
R uses binary database format for installed packages to pack the objects into a database-alike file format for efficiency reasons (lazy loading). These database files (*.rdb and *.rdx) are stored in the R sub folder of the package installation path (see ?lazyLoad).
Even if
you are looking at the right place to find the installed package (use .libPaths() in R to find the installation folder)
and you have installed the package with the source code (like you did or
via install.packages("a_CRAN_package", INSTALL_opts = "--with-keep.source"))
you will not find R files in R folder there.
You can verify that the source code is available by picking one function name from the package and print it on the console. If you can see the source code (with comments) the package sources (R files) are available:
print(DeSeq2::any_function)
To make the source code available for debugging and stack traces you can set the option keep.source.pkgs = TRUE (see ?options) in your .Rprofile file or via an environment variable:
keep.source.pkgs:
As for keep.source, used only when packages are
installed. Defaults to FALSE unless the environment variable
R_KEEP_PKG_SOURCE is set to yes.
Note: The source code is available then only for newly installed and updated packages (not for already installed packages!).
For more details see: https://yetanothermathprogrammingconsultant.blogspot.de/2016/02/r-lazy-load-db-files.html

What is the difference between a library and a package in R?

In R what is the difference between a library and a package?
I have come across posts where people refer to packages within a library. Based on this idea I interpret it that a package lives in a library (i.e I store my packages with a designated library). However I get confused when I want to use package 'x'.
I am under the imperssion I need to call the library function to get package 'x' to be in use ?
And once I have have called upon package 'x' the functions of package 'x' then become available to me ?
In R, a package is a collection of R functions, data and compiled code. The location where the packages are stored is called the library. If there is a particular functionality that you require, you can download the package from the appropriate site and it will be stored in your library. To actually use the package use the command "library(package)" which makes that package available to you. Then just call the appropriate package functions etc.
1. Package
Package extends basic R functionality and standardizes the distribution of code. For example, a package can contain a set of functions relating to a specific topic or tasks.
Packages can be distributed as SOURCE (a directory with all package components), BINARIES (contains files in OS-specific format) or as a BUNDLE (compressed file containing package components, similar to source).
The most basic package, for example created with,
library(devtools)
create("C:/Users/Documents/R-dev/MyPackage")
contains:
R/ directory where all the R code goes to, and DESCRIPTION and NAMESPACE metadata files.
2. Library
Library is a directory where the packages are stored. You can have multiple libraries on your hard drive.
To see which libraries are available (which paths are searched for packages):
.libPaths()
And to see which packages are there:
lapply(.libPaths(), dir)
To use package ‘x’, it first has to be installed in a package library. This can be done for example, with:
install.packages(‘x’) # to install packages from CRAN
or
R CMD INSTALL Xpackagename.tar.gz #to install directly from source
Once installed it has to be loaded into memory with library(x) or require(x).

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/

Resources