I am trying to run through a mixed stock analysis in RStudio based on the walkthrough provided by Bolker (https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=043730a02b148396ebd54b2f62e8f6364714b1b2), using the 'mixstock' package and the example 'lahanas98raw' dataset within. However, I am receiving a warning that the 'calc.RL.0' function cannot be found whilst trying to carry out Raftery and Lewis convergence diagnostics (p.14 of Bolker's walkthrough). I am wondering whether one of the packages has not installed properly (i.e., either 'mixstock' or 'coda'), or whether there is another package I can use to run this diagnostic instead.
When I initially tried to install the 'mixstock' package, the following warning came up:
'Warning in install.packages : package ‘mixstock’ is not available for this version of R.'
I tried installing the version of R (2.14.1) described as the 'current version of R' on page 2 of Bolker's walkthrough, but when I then tried to switch to this version of R in RStudio via the options menu, it says that this version of R is not compatible with RStudio. To work around this, I downloaded the 'mixstock' package (version 0.9.5.1) from the CRAN archive (https://cran.r-project.org/src/contrib/Archive/mixstock/) and uploaded it to RStudio this way instead.
This seemed to have worked, as I successfully ran through a significant amount of the code, but a new error arose when I tried to run Raftery and Lewis convergence diagnostics (p.14). When I try to run calc.RL.0(mydata), I receive the following error:
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
However, when I click on 'mixstock' in the package window, everything seems fine and the 'calc.RL.0' function appears, alongside several other 'calc' functions (e.g. 'calc.GR', 'calc.mult.GR', 'calc.mult.RL') that can all be found and run fine. The 'calc.RL.0' function relies on the 'raftery.diag' function within the 'coda' package, so I have also made sure that is installed and called. I have tried a bunch of other methods but nothing seems to be working.
Here is some of my code leading up to the warning message:
## Calculate confidence intervals - i.e., bootstrapping - and plot them
mydata.umlboot = genboot(mydata,"uml")
confint(mydata.umlboot)
plot(mydata.umlboot, ylim=c(0,1))
## Carry out Markov Chain Monte Carlo (MCMC) estimations and plot them
mydata.mcmc = tmcmc(mydata)
mydata.mcmc
confint(mydata.mcmc)
plot(mydata.mcmc, ylim=c(0,1))
## Check that the Markov chains have converged = run Raftery and Lewis diagnostics
library(mixstock)
library(coda)
calc.RL.0(mydata)
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
Could this be something to do with the way the 'mixstock' package was initially installed, or is it likely to be another issue? Is there another way to run Raftery and Lewis diagnostics and still get the outputs I need (diagnostics for the last chain evaluated; the history of how long each suggested chain was)? Any help would be much appreciated - thanks in advance!
The most reliable way to install mixstock, if you have development tools installed on your computer (compilers etc.), is remotes::install_github("bbolker/mixstock") (I don't think I've changed anything/fixed any bugs since the archived version, but if I did the changes would be reflected on GitHub.)
It looks like I forgot to export that function, so
mixstock:::calc.RL.0(mydata)
should work (this is something I can/should fix). Note that the Gelman-Rubin diagnostic (calc.GR(), which is properly exported) is more reliable than Raftery-Lewis anyway ...
Related
My goal is to analyse simple point patterns on linear networks with respect to Euclidean distance instead of shortest-path distance implemented in linearK and related functions of spatstat and its sub packages. Browsing through the web I found the promising named function linearKEuclid() and related functions here.
Unfortunately, I could not bring those functions to live on my Win machine, e.g. I run in errors like this
Error in xysegMcircle(Y$x, Y$y, D, df$x0, df$y0, df$x1, df$y1) :
object 'C_circMseg' not found
or
Error in tapply(stuff$sinalpha, list(ii, jj), harmonicsum) :
object 'harmonicsum' not found
There is always something missing. For me, this means simply copying missing functions from the web, if available, does not help.
Probably, a reason for this is that the functions are merely written for internal purposes and under internal development, see, for instance, here under "Details".
However, I am hoping for some recommendation making the fascinating code around linearKEuclid() runnable on my machine. Maybe, there are some chances that someone draws my attention to a downloadable developer version or something comparable. Many thanks in advance!
I understand your confusion and it is unnecessarily complicated to get this to work at the moment since problems with another package on CRAN prevents spatstat and subpackages to be updated at the moment. Indeed you need to install a development version of spatstat.linnet and its dependencies. This is most easily done if you have the package remotes installed (and necessary tools to compile packages from source which would be RTools on Windows):
First run (in sequence):
remotes::install_github("spatstat/spatstat.random")
remotes::install_github("spatstat/spatstat.sparse")
remotes::install_github("baddstats/spatstat.explore")
remotes::install_github("baddstats/spatstat.model")
remotes::install_github("spatstat/spatstat.linnet")
Now the function should work (you may have to restart R if an old version of spatstat.linnet was already loaded when you updated). Try e.g. the example from the help file:
library(spatstat.linnet)
X <- rpoislpp(5, simplenet)
K <- linearKEuclid(X)
Today I have tried to prepare a new CRAN update for a package and have come across a warning, while performing devtools::check().
Since this warning also occurs without my changes I made to the package, I am assuming this is a new check. Unfortunately I don't really get what I am supposed to do.
This is the error message:
A complete check needs the 'checkbashisms' script.
See section ‘Configure and cleanup’ in the ‘Writing R Extensions’
manual.
Of course I took a look at the section ‘Configure and cleanup’ as proposed in the warning. But still, I am not sure what to do exactly. I got, there is a checkbashisms Perl script I can download somewhere on the internet (but this alone won't make this message disappear). How shall I integrate this, that the message actually disappears.
Any hints or comments would be extremely helpful to me.
Here is a link to the repo of the package in case you want to clone it to reproduce the error.
I submitted a package to CRAN and they asked me to replace \dontrun{} by \donttest{} in the Rd-files and resubmit. I was using \dontrun{} to wrap some examples that are supposed to throw error messages.
After replacing \dontrun{} by \donttest{} I conducted some tests and R CMD check still succeeds but it happens that now both devtools::check() and R CMD check --as-cran fail due to the examples wrapped in \donttest{}:
checking examples with --run-donttest ... ERROR
After some browsing I learned that R 4.0.0 has changed R CMD check --as-cran to run \donttest examples. According to the NEWS of R-devel:
"R CMD check --as-cran now runs \donttest examples (which are run by example()) instead of instructing the tester to do so. This can be temporarily circumvented during development by setting environment variable R_CHECK_DONTTEST_EXAMPLES to a false value."
Since I intend to resubmit the package to CRAN, setting _R_CHECK_DONTTEST_EXAMPLES_ to false locally will not help me.
I also found this recent discussion in a devtools issue where Hadley Wickham states that:
"Generally, now if you don't want to run tests on CRAN \dontrun{} is more likely to work, but using \dontrun{} may cause initial submission to fail."
So now I don't know how to proceed because if I resubmit the package with the required changes I already know it will throw an error in R CMD check --as-cran, and hence it will probably fail CRAN's automatic pretests.
EDIT:
As suggested here I tried if(interactive()){} instead of \dontrun{}. This solution succeeds in R CMD check --as-cran and devtools::check() but I don't think it is the most appropriate way to address this problem since it does not work well with example() (throws an error and does not show the remaining examples). \dontrun{} works better with example() as it prints all the examples but comments out the ones wrapped with \dontrun{}.
If you know that something will throw an error, you can wrap it in try().
## example of failing code
try(stop("Here is an error"))
I don't think the package examples are the right place for "examples that are supposed to throw error messages".
Your problem would be easily solved when you move these 'examples' to testthat unit tests.
There is
expect_error()
expect_warning()
to see if your package throws a warning/error as expected.
If you really want to inform users about what they should avoid to input, maybe you can just add it as a comment to the examples or into the other documentation (details, param)
What you see quite regularly in other package examples is the following:
## Example for working
function(x, abc = "5)
## This would give an error because
# function(x, abc = "falsch")
## Working example 2
function(x)
x <- x+y
Slightly different versions of this question have been asked before but I haven't seen a good answer yet.
I have a very simple repro using the very good source code of ggplot2:
Go into any file in ggplot2/R/ and add a line that references the "diamonds" dataset included in ggplot2/data/diamonds.r.
Then attempt to build/check the package, (ie: R CMD build .; R CMD check --as-cran ggplot2_3.0.0.9000.tar.gz)
In my arbitrary example I added diamonds to line 436 in theme.r and got this note when trying to check:
* checking R code for possible problems ... NOTE
plot_theme: no visible binding for global variable ‘diamonds’
Undefined global functions or variables:
diamonds
I run into this problem in our package which we want to submit to CRAN. AFAIK we are following best practices by using data/ourdataset.r and then "ourdataset" in our R/ code. And yet, we get this NOTE failure.
What are we doing wrong? If this NOTE comes up for a package like ggplot2, I am at a loss as to whether we are doing something wrong or this is something that should be fixed in CHECK. CHECK has been fantastic so far but I am stumped on this one.
Thanks!
Usually, to get rid of that Note you just have to add a reference like this:
ggplot2::diamonds
I would like to apply the function 'fit.tcopula' from the package 'QRM' - Quantitative Risk Management and get the following error message:
fit.tcopula(Udata, method = 'Kendall')
Error: could not find function "forceAndCall"
Since I have applied the 'Udata' to different copulas from the package 'copula' already - and it worked fine - I assume the input is not an issue.
To my understanding 'forceAndCall' is part of the base package. I use the R version 3.1.3.
According to the documentation the QRM package depends R(>=3.0.1), so my version should be OK. However, listing all functions of my base package with
library(help = 'base')
reveals that the forceAndCall-Function is not there. What would the remedy be? Installing R version 3.2.1?
The reason I ask and not just do it is that I do not possess admin rights for my PC and therefore would be happy to get an opinion beforehand.
I posted the question though I already have the answer as it might be interesting to others.
Upgrading to R version 3.2.1 is the/one solution to the problem!