Skip to content

[R-pkg-devel] Errors in my package

4 messages · Steven Spiriti, Georgi Boshnakov, Duncan Murdoch +1 more

#
To Whom It May Concern:

    I have created a package called "freeknotsplines" in R, and I need to
make a few updates to it.  I resubmitted the package, and received the
following error message:

checking examples ... ERROR
Running examples in ?freeknotsplines-Ex.R? failed
The error most likely occurred in:
Error: $ operator not defined for this S4 class
Execution halted

     This error occurs in one of the examples in the documentation.   It is
platform dependent, and does not occur on the machine I am using to create
the package.  freekt is a new class, which is intended to be a S3 class,
not a S4 class.

 Here is the code for coef.freekt:

coef.freekt <- function(object, ...)
{
  xdat <- object at x
  ydat <- object at y
  optknot <- object at optknot
  ord <- object at degree + 1
  lambda <- object at lambda
  fulloptknot <- c(rep(min(xdat), ord), optknot, rep(max(xdat), ord))  #
includes endpoints
  Xmat <- splineDesign(fulloptknot, xdat, ord)
  if ((lambda == 0) | (length(optknot) == 0))
    coef <- solve(t(Xmat)%*%Xmat, t(Xmat)%*%ydat)
  else
    {
      numknots <- length(optknot)
      Amat <- chgbasismat(fulloptknot, ord)
      Istar <- diag(c(rep(0, times = ord), rep(1, times = numknots)))
      coef <- solve(t(Xmat)%*%Xmat + lambda*t(Amat)%*%Istar%*%Amat,
                    t(Xmat)%*%ydat)
    }
  return(coef)
}

Can someone please help me figure out what I am doing that is causing this
error?

Sincerely,

Steven Spiriti
#
Well, the computer is very good at doing what we ask it to, not what we intend to.

In your case coef.freekt() clearly expects an S4 object (clue: object@) and apparently that's what you feed it with.
A simple way to see where the problem actually comes from is
Then explore what is going on.

Georgi Boshnakov 

-----Original Message-----
From: R-package-devel [mailto:r-package-devel-bounces at r-project.org] On Behalf Of Steven Spiriti
Sent: 24 May 2018 21:11
To: r-package-devel at r-project.org
Subject: [R-pkg-devel] Errors in my package

To Whom It May Concern:

    I have created a package called "freeknotsplines" in R, and I need to
make a few updates to it.  I resubmitted the package, and received the
following error message:

checking examples ... ERROR
Running examples in ?freeknotsplines-Ex.R? failed
The error most likely occurred in:
Error: $ operator not defined for this S4 class
Execution halted

     This error occurs in one of the examples in the documentation.   It is
platform dependent, and does not occur on the machine I am using to create
the package.  freekt is a new class, which is intended to be a S3 class,
not a S4 class.

 Here is the code for coef.freekt:

coef.freekt <- function(object, ...)
{
  xdat <- object at x
  ydat <- object at y
  optknot <- object at optknot
  ord <- object at degree + 1
  lambda <- object at lambda
  fulloptknot <- c(rep(min(xdat), ord), optknot, rep(max(xdat), ord))  #
includes endpoints
  Xmat <- splineDesign(fulloptknot, xdat, ord)
  if ((lambda == 0) | (length(optknot) == 0))
    coef <- solve(t(Xmat)%*%Xmat, t(Xmat)%*%ydat)
  else
    {
      numknots <- length(optknot)
      Amat <- chgbasismat(fulloptknot, ord)
      Istar <- diag(c(rep(0, times = ord), rep(1, times = numknots)))
      coef <- solve(t(Xmat)%*%Xmat + lambda*t(Amat)%*%Istar%*%Amat,
                    t(Xmat)%*%ydat)
    }
  return(coef)
}

Can someone please help me figure out what I am doing that is causing this
error?

Sincerely,

Steven Spiriti


______________________________________________
R-package-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel
#
On 24/05/2018 4:11 PM, Steven Spiriti wrote:
But you are using the @ operator on it:
That's normally something that you would do with an S4 object.  We can't 
tell from your posting what xy.freekt really is; maybe it would help if 
you posted the result of str(xy.freekt) after creating it.

Duncan Murdoch
#
On Thu, May 24, 2018 at 10:11 PM, Steven Spiriti <puzzlesteven at gmail.com>
wrote:
The error and the code of the function tell me there is a problem with
dispatching. You treat xy.freekt as an S4 class and R thinks so too. The
coef generic is S3. The default method for this generic extracts
object$coefficients, and that can't work on an S4 class. This would explain
the error you see: instead of using the appropriate method, the dispatching
apparently uses the default S3 method.

Can you link us to a github repo or so where we can see the code? I suspect
either a problem with the NAMESPACE or with the class definitions. Are you
sure freelsgen returns the class you expect it to return?

Cheers
Joris