I have created and downloaded an R package using roxygen2 development tools. When I update the source code R files, the documentation updates fine, but the function code itself does not. How do I get the function code to update when I reinstall the package with install.packages("package-name")?
I have tried inserting error messages at the beginning of every function using stop("..."). When I reinstall the code, the functions do not output an error message as they should but work as they did before I updated the code.
Each time I update the code, I use the following commands:
devtools::document()
devtools::install()
install.packages("package-name", repos=NULL, type="source")
library(package-name)
Just for further information, when I try to install the package this way:
install.packages("package-name")
I get the following error message:
Warning in install.packages :
package ‘package-name’ is not available (for R version 3.6.0)
I got this same error message when my R version was 3.6.0, and even now after updating to 3.6.1
I have not uploaded the package to any repositories, so I figured this makes sense, and instead install it locally from my package files with repos=NULL.
#' Roxygen comments - this part updates
#'
#' etc.
functionName <- function(...) {
stop("...")
...
# This function should crash with an error message every time it is called,
# but instead the function body is never updated.
}
Upon reinstalling the package, I expect the output of my functions to be an error message, but instead, they output the same result as they did before I updated the package.
Documentation updates, function bodies do not.
So it turns out I found an answer to my own question...
The problem was with a warning message I was getting:
Warning message:
In body(fun) : argument is not a function
Despite not ever using body(), this function was getting called internally somewhere, and the warning prevented the code from being updated (but the documentation still updates, for some reason).
Clearing my global environment with rm(list=ls()) cleared my error.
Related
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!
Code:
install.packages("biotools")
library(biotools)
boxM(train1[,2:6],train1[,1])
Error:
Error in boxM(train1[, 2:6], train1[, 1]) : could not find function
"boxM"
The package has been installed successfully as per console. Even after checking the checkbox for enabling the library, getting the same issue.
You may try "heplots" package. It contains boxM function as well.
I am rebuilding documentation in a custom package in RStudio. Running R version 3.5.1. I am able to rebuild the package. However, when I run Document from the RStudio Build pane (or the shift+com+D shortcut), I get an error:
Error in (function (dep_name, dep_ver = NA, dep_compare = NA) :
Dependency package qdap not available.
Now, if I run devtools::document() from the console without any arguments, it runs with no problems. Note that qdap is listed in the DESCRIPTION files under imports.
Note that the first time I do this, R prompts me to manually install several packages because the previous versions were built under different internals from the new R 3.5.1 version.
I would like to understand what exactly is going on here - why am I getting the error that qdap isn't being found?
I am trying to use this source from github.
devtools::source_url('https://raw.githubusercontent.com/brooksandrew/Rsenal/master/R/bin.R')
I could use this and work with it till few hours back. but now it gives me the following error
Error in loadNamespace(name) : there is no package called ‘Rsenal’
The code is still there in the provided url. I did re run the following two commands but still not working.
install.packages("devtools")
library("devtools")
What should I do to fix this issue?
I believe your issue is arising because you are sourcing functions that live inside a package, that is meant to be distributed as a package.
Instead of using devtools::source_url(), try this:
devtools::install_github('brooksandrew/Rsenal')
library("Rsenal")
Once the package is properly installed, all of the primary functions (such as binCat()) should be available for use.
I believe you ran into this error because some functions within the package probably depend on others that are not found within the two files you manually sourced. So when those lines are executed, R looks for the Rsenal package file and does not find them.
Further troubleshooting would require a reproducible example.
I am using R 3.2.2 and installed the mosaic package. I then used the fetchData function as follows:
data<-fetchData(1,c("Web_scraping","Data_mining"))
I get the following error:
Error: Use fetchData() from the `fetch' package instead.
When I try to install the fetch package, an error says:
Warning in install.packages :
package ‘fetch’ is not available (for R version 3.2.2)
I found documentation that the mosaic package was dropping fetchData in R 3.2.2, but couldn't find what package I should use to run the function properly.
Fetch
It appears that the fetch package is currently available via GitHub at https://github.com/ProjectMOSAIC/fetch.
Installation
To install fetch from GitHub:
Open up your R console
Install devtools (if not already installed) with this command*:
install.packages("devtools")
Type y if going through the devtools installer
Install fetch with this command:
devtools::install_github("ProjectMOSAIC/fetch")
Basic Usage
If successful, fetch should be accessible by requiring the fetch package
require("ProjectMOSAIC/fetch")
and calling fetchData() like this:
data <- fetch::fetchData( ... )
* Note: According to Etienne Low-Décarie, you'll need to have the make command available on your system before running the install.packages("devtools") command.
My students have been running into this problem trying to use the textbook code from Statistical Modeling: A Fresh Approach, this semester. I'm not familiar with the syntax used in the original question (with the number as the first argument), but this does not appear to be supported syntax in the fetch::fetchData() function. The workflow that we have been using to get around this (slightly simpler than summea's answer) is:
install.packages("devtools")
devtools::install_github("ProjectMOSAIC/fetch")
data <- fetch::fetchData("whickham.csv")
Note that I cannot reproduce the example in the original question, as I get different error/warning messages:
data<-fetch::fetchData(1,c("Web_scraping","Data_mining"))
With this as the error/warning:
Error in if (show.path) return(get("path", envir = .fetchEnvironment)) :
argument is not interpretable as logical
In addition: Warning message:
In if (show.path) return(get("path", envir = .fetchEnvironment)) :
the condition has length > 1 and only the first element will be used
I hope fetch is on its way to being on CRAN, and listed as a dependency of mosaic, as this is currently causing headaches in my class.