Package ceases to work due to "if" error: condition has length > 1

Viewed 172

I am using package splm and I'm getting an error:

#kkp: spatial autocorrelation related to individual RE
panel.SARAR.RE <- spml(formula = fm, data = rynekpracy.panel, 
                        model = "random",
                        listw = W.crosssec.list, lag = TRUE,
                        spatial.error = "kkp")

Error in if (class(covTheta) == "try-error") { : 
  the condition has length > 1

Does anyone know how to cope with this? I looked up in the internet but unfortunately couldn't find anything. Thank you for helping.

2 Answers

The post akrun referred you to explains why it is dangerous to write code like:

if (class(foo) == "bar")

The correct way to do (not mentioned in that post, unfortunately) is:

if (inherits(foo, "bar"))

But this is not your coding problem. You are using package splm, and it is the package to blame. Are you aware of the significant change in R 4.2.0? See R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)'? This puts lots of packages in trouble. Packages that failed to adapt to this change, even if they used to work smoothly, will now throw warnings or errors!

I don't know why splm is still on CRAN. I would expect it to be removed from CRAN, given that it failed to fix its code in time. In the latest release, splm_1.5-3, we could see:

sarem2REmod.R:    if(class(covTheta) == "try-error") {
sarem2srREmod.R:    if(class(covTheta) == "try-error") {
saremmod.R:    if(class(covTheta) == "try-error") {
saremREmod.R:    if(class(covTheta) == "try-error") {
saremsrmod.R:    if(class(covTheta) == "try-error") {
saremsrREmod.R:    if(class(covTheta) == "try-error") {
sem2REmod.R:    if(class(covTheta) == "try-error") {
sem2srREmod.R:    if(class(covTheta) == "try-error") {
semmod.R:    if(class(covTheta) == "try-error") {
semREmod.R:    if(class(covTheta) == "try-error") {
semsrmod.R:    if(class(covTheta) == "try-error") {
semsrREmod.R:    if(class(covTheta) == "try-error") {
sparseBmethods.R:        if (class(J1) == "try-error") {

Contact its package maintainer (with a link of this post) and report bugs.


clarification

CRAN checks can only detect problems that occur at installation time. At best, it could check whether all examples in the documentation could run smoothly. However, it can not detect all bugs. This explains why CRAN is still happy with the package.

Maintainer here. A corrected version of splm, 1.5-5, is on its way to CRAN. And no, you don't "get removed" from CRAN if you have a bug: especially if you have many thousands of users. Bugs are reported, then fixed.

Related