Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird failure with dev evaluate #73

Closed
hadley opened this issue Aug 21, 2024 · 9 comments
Closed

Weird failure with dev evaluate #73

hadley opened this issue Aug 21, 2024 · 9 comments
Assignees

Comments

@hadley
Copy link

hadley commented Aug 21, 2024

When I run create.poped.database() inside evaluate, I get an error:

library(PopED)
sfg <- function(x,a,bpop,b,bocc){
  c(
    V=bpop[1]*exp(b[1]),
    KA=bpop[2]*exp(b[2]),
    CL=bpop[3]*exp(b[3])*bpop[5]^a[3], # add covariate for pediatrics
    Favail=bpop[4],
    isPediatric = a[3],
    DOSE=a[1],
    TAU=a[2]
  )
}

evaluate::evaluate("create.poped.database(
    ff_fun=ff.PK.1.comp.oral.md.CL,
    fg_fun=sfg,
    fError_fun=feps.add.prop,
    bpop=c(V=72.8,KA=0.25,CL=3.75,Favail=0.9,pedCL=0.8),
    notfixed_bpop=c(1,1,1,0,1),
    d=c(V=0.09,KA=0.09,CL=0.25^2),
    sigma=c(0.04,5e-6),
    notfixed_sigma=c(0,0),
    m=2,
    groupsize=20,
    xt=c( 1,8,10,240,245),
    bUseGrouped_xt=1,
    a=list(c(DOSE=20,TAU=24,isPediatric = 0),
           c(DOSE=40, TAU=24,isPediatric = 0))
  )
")
#> <evaluation>
#> Source code: 
#>   create.poped.database(
#>       ff_fun=ff.PK.1.comp.oral.md.CL,
#>       fg_fun=sfg,
#>       fError_fun=feps.add.prop,
#>       bpop=c(V=72.8,KA=0.25,CL=3.75,Favail=0.9,pedCL=0.8),
#>       notfixed_bpop=c(1,1,1,0,1),
#>       d=c(V=0.09,KA=0.09,CL=0.25^2),
#>       sigma=c(0.04,5e-6),
#>       notfixed_sigma=c(0,0),
#>       m=2,
#>       groupsize=20,
#>       xt=c( 1,8,10,240,245),
#>       bUseGrouped_xt=1,
#>       a=list(c(DOSE=20,TAU=24,isPediatric = 0),
#>              c(DOSE=40, TAU=24,isPediatric = 0))
#>     )
#> Condition: 
#>   Error in poped.db$parameters$bpop[, 2, drop = F]:
#>   incorrect number of dimensions

Created on 2024-08-21 with reprex v2.1.0

But if I run this code directly, it works.

This is a problem because knitr uses evaluate to run code, which means that your vignette breaks with dev evaluate. I think this is most like'y because you're looking in some evaluation frame that you shouldn't, but unfortunately I don't know enough about PopED to diagnose the problem (and if there's anything I can do in evaluate to fix it).

@hadley hadley mentioned this issue Aug 21, 2024
10 tasks
@andrewhooker andrewhooker self-assigned this Aug 29, 2024
@andrewhooker
Copy link
Owner

Hi Hadley,

When I run the above code, in the released version of both packages (PopED and evaluate), I can't reproduce your error. I don't get an error with any combination of released and latest development versions either. I am using the latest R version on an M3 Mac with the latest OS. What versions of the packages were you using? What environment are you using?

Best regards,
Andy

@hadley
Copy link
Author

hadley commented Sep 5, 2024

I'm using dev evaluate and CRAN versions of everything else.

@andrewhooker
Copy link
Owner

andrewhooker commented Sep 6, 2024

Hi

I have successfully reproduced the issue. Running the code line-by-line in an interactive R session does not produce any errors. However, when I knit the code in a vignette/R Markdown document or use reprex, I encounter the error shown below. Although I haven’t pinpointed the exact cause yet, I can now experiment further to understand the problem.

Best regards,
Andy

library(PopED)
packageVersion("PopED")
#> [1] '0.6.0'
packageVersion("evaluate")
#> [1] '0.24.0.9000'

sfg <- function(x,a,bpop,b,bocc){
  c(
    V=bpop[1]*exp(b[1]),
    KA=bpop[2]*exp(b[2]),
    CL=bpop[3]*exp(b[3])*bpop[5]^a[3], # add covariate for pediatrics
    Favail=bpop[4],
    isPediatric = a[3],
    DOSE=a[1],
    TAU=a[2]
  )
}

create.poped.database(
  ff_fun=ff.PK.1.comp.oral.md.CL,
  fg_fun=sfg,
  fError_fun=feps.add.prop,
  bpop=c(V=72.8,KA=0.25,CL=3.75,Favail=0.9,pedCL=0.8),
  notfixed_bpop=c(1,1,1,0,1),
  d=c(V=0.09,KA=0.09,CL=0.25^2),
  sigma=c(0.04,5e-6),
  notfixed_sigma=c(0,0),
  m=2,
  groupsize=20,
  xt=c( 1,8,10,240,245),
  bUseGrouped_xt=1,
  a=list(c(DOSE=20,TAU=24,isPediatric = 0),
         c(DOSE=40, TAU=24,isPediatric = 0))
)
#> Error in poped.db$parameters$bpop[, 2, drop = F]: incorrect number of dimensions

evaluate::evaluate("create.poped.database(
    ff_fun=ff.PK.1.comp.oral.md.CL,
    fg_fun=sfg,
    fError_fun=feps.add.prop,
    bpop=c(V=72.8,KA=0.25,CL=3.75,Favail=0.9,pedCL=0.8),
    notfixed_bpop=c(1,1,1,0,1),
    d=c(V=0.09,KA=0.09,CL=0.25^2),
    sigma=c(0.04,5e-6),
    notfixed_sigma=c(0,0),
    m=2,
    groupsize=20,
    xt=c( 1,8,10,240,245),
    bUseGrouped_xt=1,
    a=list(c(DOSE=20,TAU=24,isPediatric = 0),
           c(DOSE=40, TAU=24,isPediatric = 0))
  )
")
#> <evaluation>
#> Source code: 
#>   create.poped.database(
#>       ff_fun=ff.PK.1.comp.oral.md.CL,
#>       fg_fun=sfg,
#>       fError_fun=feps.add.prop,
#>       bpop=c(V=72.8,KA=0.25,CL=3.75,Favail=0.9,pedCL=0.8),
#>       notfixed_bpop=c(1,1,1,0,1),
#>       d=c(V=0.09,KA=0.09,CL=0.25^2),
#>       sigma=c(0.04,5e-6),
#>       notfixed_sigma=c(0,0),
#>       m=2,
#>       groupsize=20,
#>       xt=c( 1,8,10,240,245),
#>       bUseGrouped_xt=1,
#>       a=list(c(DOSE=20,TAU=24,isPediatric = 0),
#>              c(DOSE=40, TAU=24,isPediatric = 0))
#>     )
#> Condition: 
#>   Error in poped.db$parameters$bpop[, 2, drop = F]:
#>   incorrect number of dimensions

Created on 2024-09-06 with reprex v2.1.1

@hadley
Copy link
Author

hadley commented Sep 9, 2024

I can no longer reproduce this with the latest dev version of evaluate so 🤞 I've fixed the problem.

@andrewhooker
Copy link
Owner

Fantastic!

@hadley
Copy link
Author

hadley commented Sep 9, 2024

I asked Kurt to run an informal series of checks and it still appears on CRAN 😞 Unfortunately there are only 7 failures out of all ~9000 packages I checked so it seems likely that it's something subtly wrong with your package, not an evaluate bug. I'm planning to submit to CRAN on Sept 16.

@andrewhooker
Copy link
Owner

Thanks for all your efforts! I'll keep investigating then!

@andrewhooker
Copy link
Owner

I am using capture.output in my package, which seems to perform differently when in an interactive session and when I knit the code in a vignette/R Markdown document or use reprex. The new version of evaluate seems to change the way capture.output performs in these non-interactive settings. This in turn has broken a set of regular expressions I am using to find specific terms in a function (I'm looking for all instances of bpop[*] for example). A fix to the regular expressions I use in PopED is on the way.

andrewhooker added a commit that referenced this issue Sep 12, 2024
…type (bpop, d, sigma, etc.) in a user defined model parameter function. (#73)
@andrewhooker
Copy link
Owner

Updated in the latest dev version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants