How to update locally created R package without reinstalling - r

I created an R package using this tutorial. The package loads just fine when called but requires a bit debugging. After debugging my script, I used devtools::update_packages("new_package") to fix the changes, but I receive the following error: Skipping 1 packages not available: new_package (interestingly, new_package shows up when I call installed.packages()).
I'm able to update my package by reinstalling with devtools::install("new_package"), but for simple fixes this doesn't seem very efficient. Perhaps there is another way? I appreciate any help or insight.
EDIT for clarification:
I understand the package needs to be reloaded to update changes, but reloading the package using library(mypackage) (after detaching the package or starting a new session) does not accomplish this while devtools::update_packages("path/to/mypackage") does. Per the tutorial, I decided to install my package using devtools::install(). Is this because the process of installing my homebrew package requires setting up repository for updates?

Related

"package or namespace load failed" error in loading R package from GitHub

I am trying to load a package in RStudio from GitHub but I get an error.
I have also updated all the packages in order to see if this was the problem but I still get the same error. I have a MAC pc (I don't know if this may cause some problems).
The link of the package that I would like to load is:
https://github.com/andrewraim/COMMultReg
and there is written that in order to load it I need to run
library(devtools)
install_github("andrewraim/COMMultReg")
But when I run the second line I get as error:
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘COMMultReg’ in namespaceExport(ns, exports):
undefined exports: d_cmb, d_cmb_sample, d_cmm, d_cmm_sample, gunterize, loglik_score_fim_cmm, normconst_cmb, normconst_cmm, r_cmb
Errore: loading failed
Esecuzione interrotta
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/COMMultReg’
Warning message:
In i.p(...) :
installation of package ‘/var/folders/n0/4lmr1lrj7qqfylmh6s8qx0nr0000gn/T//RtmpldrmHr/file72e1e4469d/COMMultReg_0.1.0.tar.gz’ had non-zero exit status
Can somebody help me telling me what to do?
Thanks!!
The package has no function named d_cmb, but it tries to export that function. That's what the error message says, and it's true.
I think the reason for this error is that the author used Roxygen2 to generate his NAMESPACE file where the exports are declared, but that file is out of sync with the contents of the package.
It's possible this happened because the author forgot to commit a new file containing the new code. In that case, the best solution is to contact the author, and point out the issue.
Alternatively, it may have happened because at one time there was a d_cmb function, but the author removed it, without updating the NAMESPACE file. This one you might be able to fix yourself.
To fix this, you'll need to run Roxygen2 yourself, which is a little more complicated than just installing what's on Github. Here are the steps:
Fork the package to your own Github account if you have one. (This step is optional, but it makes some later steps easier.)
Download the source for the package. In RStudio, the quickest way to do this is to create a new project using Version Control, Git, and give the URL
of your forked copy, or the original URL if you skipped that.
Run Roxygen2 on the package. In RStudio, you do this by choosing "Document" in the "More" menu of the Build tab.
Try to build it. If you're lucky, it will now build properly. If not, fix the next problem.
This is very important: send your changes back to the original author. If you forked the package, this is easy; if not, figure out a way to do it.
this is the maintainer of the COMMultReg package. I didn't know about this thread until now, but it sounds like you were able to get started from the answer by user2554330.
The functions d_cmb, d_cmb_sample, etc are supposed to be exported. I think the problem may have been that, at the time of the question, I did not have src/RcppExports.cpp and R/RcppExports.R checked into Github. This seems to be necessary to use install_github on a package with exported Rcpp functions. Those were checked in around 8 months ago. (Coincidentally not long after this question was posted?)
Please let me know if you still having trouble with the install. Otherwise, enjoy the package!

Facing trouble in loading packages in R studio [duplicate]

I updated R using installr and asked to copy my library. (Even though I've never had this work, I keep hoping maybe it will someday as the package gets updated.) Opened up RStudio and, as usual, it can't find any of the packages that were in my old library. I next copied all the files from my old library into my new library, and several critical ones still don't work. For example, when I tried to load tidyverse, the message I receive is:
Error: package or namespace load failed for ‘tidyverse’: package ‘lazyeval’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version.
I tried remove.packages("tidyverse") and then install.packages("tidyverse", dependencies = TRUE), and I still get the same message about the package lazyeval. I tried installing lazyeval, but then, when I go through those same steps again to try to use tidyverse, now it's lubridate that was installed by an R version with different internals.
How can I avoid this incredibly irritating and time-sucking iterative process of trying to install a package, seeing that the internals are wrong for some dependent package, installing whatever package was the problem, installing the package I actually care about, and then figuring out what other dependencies are problems?
The tidyverse package hardly contains anything: its main purpose is to get a bunch of other packages loaded. Removing it and updating it won't help update the other packages. You could do what #phago29 suggested in their comment, but an easier way is just to update everything. Run this command in an R session:
update.packages(ask = FALSE, checkBuilt = TRUE)
A few notes:
If you have admin capabilities, run as admin, and it will update your main library. If you don't, it'll install new copies in your user account.
Even though you're saying ask = FALSE, it may ask some questions about whether you can build packages from source. Answer "Yes" if your system is set up to do that, "No" if not. If you're not sure, try "Yes", and if you get install failures, run it again and say "No".)
This is likely to run for a while, so go away and have a coffee or something.

Updated R, copied library, still can't find packages, and can't seem to install all dependencies

I updated R using installr and asked to copy my library. (Even though I've never had this work, I keep hoping maybe it will someday as the package gets updated.) Opened up RStudio and, as usual, it can't find any of the packages that were in my old library. I next copied all the files from my old library into my new library, and several critical ones still don't work. For example, when I tried to load tidyverse, the message I receive is:
Error: package or namespace load failed for ‘tidyverse’: package ‘lazyeval’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version.
I tried remove.packages("tidyverse") and then install.packages("tidyverse", dependencies = TRUE), and I still get the same message about the package lazyeval. I tried installing lazyeval, but then, when I go through those same steps again to try to use tidyverse, now it's lubridate that was installed by an R version with different internals.
How can I avoid this incredibly irritating and time-sucking iterative process of trying to install a package, seeing that the internals are wrong for some dependent package, installing whatever package was the problem, installing the package I actually care about, and then figuring out what other dependencies are problems?
The tidyverse package hardly contains anything: its main purpose is to get a bunch of other packages loaded. Removing it and updating it won't help update the other packages. You could do what #phago29 suggested in their comment, but an easier way is just to update everything. Run this command in an R session:
update.packages(ask = FALSE, checkBuilt = TRUE)
A few notes:
If you have admin capabilities, run as admin, and it will update your main library. If you don't, it'll install new copies in your user account.
Even though you're saying ask = FALSE, it may ask some questions about whether you can build packages from source. Answer "Yes" if your system is set up to do that, "No" if not. If you're not sure, try "Yes", and if you get install failures, run it again and say "No".)
This is likely to run for a while, so go away and have a coffee or something.

Trouble accessing help documentation for a package I created

I'm new to R so I hope this isn't incredibly obvious. I created a package that contains two functions. I provided documentation using roxygen2 for each of the functions, documented and built the package as well as installed and restarted multiple times. I also pushed it up to github and have done everything I can think of to do, yet I cannot access the help files that I created. I always receive this error:
No documentation for ‘myfunc’ in specified packages and libraries: you
could try ‘??myfunc’
Not only is ?myfunc not working, but when I attempt to install my own package to my own RStudio console, but I also receive this error:
Warning in install.packages : package ‘yourpackage*’ is not
available (for R version 3.6.1)
What exactly is going wrong here, and how can I attempt to fix it? I've built packages before and this time I've followed all the same steps I've been taught to use and have used in the past, but for some reason, I'm being met with these errors. I would appreciate any and all help you all have to offer. Thank you in advance!

Reload updated package in 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

Resources