Reload updated package in R - r

I used to develop some package for R. So, this is an iterative process where I need to check the working of the package in between by installing it via rstudio, and then again adding some necessary functionalities. So, I used the following process:
create a R package
install it via command prompt: R CMD install <{package_name}>
load the package in rstudio as, library(package_name)
Check the necessary functionality
detach package in rstudio using, detach(package:{package_name})
remove package via command prompt as: R CMD remove <{package_name}>
add/update package
repeat steps 2 - 7,until package is fully developed.
Now the problem is that everytime I close rstudio after step 5, otherwise updated package after installation is not reflected in R.
So, How can I avoid to close rstdio everytime; and always get updated copy of installed package. In other words, I don't want to close rstudio everytime. I have found that detach( ) is not effective.
Note: I use rstudio only for checking the functionality of package. I check,build for building packages on command prompt using R CMD check/build commands

RStudio has functionality for building packages that I does what I think you have described.
Basically, use 'new project' and select the R-package option or just open an old project using the '.Rproj' file
Then use the build and reload each time you make a change to the package
and want to reload the package in (see pic).
Seems to work OK for me.
See link for more details:
https://support.rstudio.com/hc/en-us/articles/200486488-Developing-Packages-with-RStudio

Related

Install R packages through "Jobs" tab in Rstudio

In Rstudio, I usually install R packages using the console by install.packages('pkg-name') command.
However, when some R packages are required in an R script, Rstudio opens a pop-up and asks if I want to install those packages. If I click on "Install", it starts installing those packages inside the "Jobs" tab. This is particularly useful for me because my internet is slow and while a large package is being installed I can continue my works on the console tab. I want to know if there is any way to always install packages through this "Jobs" tab, without using the console.
There's an R package {job} which can be used to run any r code directly from a script or console. To install a package as a Rstudio job:
# install.packages("job")
job::job({
install.packages("pkg_name")
})
Also {job} provides Rstudio Addins to easily run selected code as a job.
see here for more examples.
You can create a script, let's call it temp.R and include the install.packages command in it. Something like :
install.packages('dplyr', repos = "http://cran.us.r-project.org")
install.packages('tidyr', repos = "http://cran.us.r-project.org")
You can click on Start Local Job
and point to the location of the script and adjust any other setting that you want.
Now click on Start and use R/RStudio while the script finishes in the background.

How can I install a package in "developer mode" in R / RStudio?

I am creating an R package, but I don't want to install and restart every time I make a change. Is there a way to install the package in developer mode, as in python, so that I can run the code that I modify?
If you aren't already I would suggest installing the devtools package. The load_all function will load your package in it's current state.
If you are building it inside RStudio, in a project, you can use CTRL + Shift + L to load the package so that you can test it interactively. This link has some basic details around setting up a package in RStudio.

Can a user of a GitHub R package avoid first installing and loading devtools

Suppose I have an R package on GitHub. Is there any way, I can have an RStudio user of my package avoid first running:
install.packages("devtools")
library(devtools)
and just directly use:
install_github("My-Github-username/My-package-name")
library(My-package-name)
Can I for example make any changes to my R package such that my package automatically does install.packages("devtools") and library(devtools) for the user?
You somehow need to get your user to install and build the package locally to use it. The package can't install itself. Think of the package as a collection of code. You somehow need to get the code from GitHub to your user's computer.
If using devtools is not an option, you could have them do this manually (by, say, downloading the .tar.gz from GitHub) and then build the package themselves, using R CMD build and R CMD install such. There are some nice explanations out there on how to go about doing this. Using devtools::install_github() is a convenient, easy function that takes care of all of those steps for you.
(The exception to my statement "The package can't install itself" is that you can use devtools to install devtools.)

How to upload arules package in R

I am not able to upload arules package
Below is the following command I am using
library(arules)
I have downloaded the file from http://cran.r-project.org/web/packages/arules/index.html still it is not able to upload it.
Can anyone help me out
install.packages("arules")
pls. find below GUI - Screen for Rcmdr Package
Open RStudio.
Go to the “Packages” tab and click on “Install Packages”. The first time you’ll do this you’ll be prompted to choose a CRAN mirror. R will download all necessary files from the server you select here. Choose the location closest to you (probably “USA CA 1” or “USA CA 2”, which are housed at UC Berkeley and UCLA, respectively).
Install packages in Windows
Start typing “Rcmdr” until you see it appear in a list. Select the first option (or finish typing Rcmdr), ensure that “Install dependencies” is checked, and click “Install”.
Install Rcmdr in Windows
Wait while all the parts of the R Commander package are installed.
I had a similar problem. I solve it using
#install and load devtools to install directly from github
install("devtools")
library("devtools")
install_github("mhahsler/arules")
If you want to install "arules" package, you may not be able to install it just using the code below.
<< install.packages("arules") >>
follow the steps in order to solve problem:
go to the package's address and download it manually.you will find it in the link below:
https://cran.r-project.org/web/packages/arules/index.html
If you are using R-Studio just install that package you have got, by "tools" menu in your IDE (R-studio)
Tools->Install packages->...
brows the file in your computer and install it.
go to the command line and using library(arules) function test the package. If there is still an error it could belong to incompatibility of the package with the version of R (Not R-Studio or any other IDE that you are using), just upgrade R and try installation period again.
I had a related problem where I could not install arules after being able to successfully install many libraries. I finally learned that I needed to update to 3.4 for arules. In order to do that, I followed duckmayr's answer HERE. Then, I was able to install arules with no issues, and it worked.

R develop packages without installing every time

I am developing an R package, but every time I make some modifications
I have to use R CMD INSTALL to install it and see if the new version
is working.
I would like to know if there is some easier way to develop a package in R.
Specifically I would like to be able to develop the package without having
to install it every time I want to test it.
If you are familiar with Python and setuptools, I would like to achieve the
same effect you get using
python setup.py develop.
Install devtools, then all you need to do is:
require(devtools)
load_all("/wherever/your/package/is")
It reloads all the changed code in .R files, recompiles, links, loads C code and so on.
devtools will also compile your documentation, and run checks.
Nothing else comes close for package development.

Resources