mclements/rstpm2

predictnl.default method is not exported/used

Closed this issue · 2 comments

Hello!
I was replicating one of the examples from the vignette on predictnl that you sent me, and I couldn't reproduce the example with the linear regression model:

library(rstpm2)
#> Loading required package: survival
#> Loading required package: splines
#> 
#> Attaching package: 'rstpm2'
#> The following object is masked from 'package:survival':
#> 
#>     colon
set.seed(123456)
x1 <- rnorm(1000)
y <- rnorm(1000, x1)
fit <- lm(y ~ x1)
invert <- function(object, newdata) {
  thetahat <- coef(object)
  (newdata$y - thetahat[1])/thetahat[2]
}
predictnl(fit, invert, newdata = data.frame(y = seq(0, 2, by = 0.5)))
#> Error in UseMethod("predictnl"): no applicable method for 'predictnl' applied 
#>  to an object of class "lm"

I was expecting the predictnl.default method to be dispatched by default, but that did not happen. However, if I call it directly (and via the ::: operator - is it not exported on purpose?) if works fine:

rstpm2:::predictnl.default(fit, invert, newdata = data.frame(y = seq(0, 2, by = 0.5)))
#>      Estimate         SE
#> 1 0.007973223 0.03208338
#> 2 0.505825537 0.03585955
#> 3 1.003677852 0.04540490
#> 4 1.501530166 0.05793476
#> 5 1.999382481 0.07190551

Should this be useful, my R session info follows:

devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.0 (2018-04-23)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United Kingdom.1252 
#>  tz       Europe/London               
#>  date     2018-05-29
#> Packages -----------------------------------------------------------------
#>  package   * version  date       source        
#>  backports   1.1.2    2017-12-13 CRAN (R 3.5.0)
#>  base      * 3.5.0    2018-04-23 local         
#>  bbmle       1.0.20   2017-10-30 CRAN (R 3.5.0)
#>  compiler    3.5.0    2018-04-23 local         
#>  datasets  * 3.5.0    2018-04-23 local         
#>  devtools    1.13.5   2018-02-18 CRAN (R 3.5.0)
#>  digest      0.6.15   2018-01-28 CRAN (R 3.5.0)
#>  evaluate    0.10.1   2017-06-24 CRAN (R 3.5.0)
#>  formatR     1.5      2017-04-25 CRAN (R 3.5.0)
#>  graphics  * 3.5.0    2018-04-23 local         
#>  grDevices * 3.5.0    2018-04-23 local         
#>  grid        3.5.0    2018-04-23 local         
#>  htmltools   0.3.6    2017-04-28 CRAN (R 3.5.0)
#>  knitr       1.20     2018-02-20 CRAN (R 3.5.0)
#>  lattice     0.20-35  2017-03-25 CRAN (R 3.5.0)
#>  magrittr    1.5      2014-11-22 CRAN (R 3.5.0)
#>  Matrix      1.2-14   2018-04-13 CRAN (R 3.5.0)
#>  memoise     1.1.0    2017-04-21 CRAN (R 3.5.0)
#>  methods   * 3.5.0    2018-04-23 local         
#>  mgcv        1.8-23   2018-01-21 CRAN (R 3.5.0)
#>  nlme        3.1-137  2018-04-07 CRAN (R 3.5.0)
#>  numDeriv    2016.8-1 2016-08-27 CRAN (R 3.5.0)
#>  Rcpp        0.12.17  2018-05-18 CRAN (R 3.5.0)
#>  rmarkdown   1.9      2018-03-01 CRAN (R 3.5.0)
#>  rprojroot   1.3-2    2018-01-03 CRAN (R 3.5.0)
#>  rstpm2    * 1.4.1    2017-09-20 CRAN (R 3.5.0)
#>  splines   * 3.5.0    2018-04-23 local         
#>  stats     * 3.5.0    2018-04-23 local         
#>  stats4      3.5.0    2018-04-23 local         
#>  stringi     1.2.2    2018-05-02 CRAN (R 3.5.0)
#>  stringr     1.3.1    2018-05-10 CRAN (R 3.5.0)
#>  survival  * 2.42-3   2018-04-16 CRAN (R 3.5.0)
#>  tools       3.5.0    2018-04-23 local         
#>  utils     * 3.5.0    2018-04-23 local         
#>  withr       2.1.2    2018-03-15 CRAN (R 3.5.0)
#>  yaml        2.1.19   2018-05-01 CRAN (R 3.5.0)

My bad, it works flawlessly using the version from the develop branch. Thanks!