metrumresearchgroup / bbr

R interface for model and project management
https://metrumresearchgroup.github.io/bbr/
Other
22 stars 2 forks source link

`model_summary` prints incorrectly #615

Closed barrettk closed 2 months ago

barrettk commented 8 months ago

Still looking into the exact cause, but model_summary() doesnt seem to print the summary correctly anymore. I assumed it was due to a recent knitr release, but after downgrading to 1.4.0 im still seeing the issue. The issue arises during this call, and can be seen when printing any model_summary object. I haven't fully ruled out the idea that my environment could be part of the problem, so I would appreciate someone else verifying they also run into this issue (after updating all packages via pkgr install).

> sum
Dataset: ../example2.csv

Records: 2400    Observations: 2000  Subjects: 400

Objective Function Value (final est. method): -10838.582

Estimation Method(s):

– Stochastic Approximation Expectation-Maximization 

– Objective Function Evaluation by Importance Sampling 

No Heuristic Problems Detected

Error in `map_chr()` at bbr/R/print.R:273:4:
ℹ In index: 1.
Caused by error in `split_l[[.i]]`:
! subscript out of bounds
Run `rlang::last_trace()` to see where the error occurred.

cc @kyleam @seth127

barrettk commented 8 months ago

Im actually starting to think I didnt have knitr installed before, and only had it for my work with the model_tree. In which case I think this code (linked in main issue) was never running before in a development environment. Im curious if scientists have run into this when calling model_summary() in rmarkdown reports where knitr is installed

kyleam commented 8 months ago

so I would appreciate someone else verifying they also run into this issue (after updating all packages via pkgr install)

I'm not able to trigger it on current tip of main (with freshly installed packages and knitr installed).

(edit: I also tried with example2_saemimp, which looks to be the example model in your output above)

details ``` $ git rev-parse HEAD c6a34e43bedb335bb5bd42edc6c4ac760c1a8cea ``` ``` > m <- read_model("inst/model/nonmem/basic/1") > model_summary(m) Dataset: ../../../../extdata/acop.csv Records: 779 Observations: 741 Subjects: 39 Objective Function Value (final est. method): 2583.311 Estimation Method(s): – First Order Conditional Estimation with Interaction **Heuristic Problem(s) Detected:** – hessian_reset |parameter_names |estimate |stderr |shrinkage | |:---------------|:--------|:------|:---------| |THETA1 |2.32 |0.0872 | | |THETA2 |54.6 |3.38 | | |THETA3 |463 |30.3 | | |THETA4 |-0.0820 |0.0561 | | |THETA5 |4.18 |1.38 | | |OMEGA(1,1) |0.0985 |0.0203 |17.5 | |OMEGA(2,2) |0.157 |0.0272 |2.07 | > packageVersion("knitr") [1] ‘1.45’ ```
barrettk commented 8 months ago

@kyleam would you mind stepping through this section of the print code, and letting me know what param_str is equal to before and after line 273? Im seeing that it's a vector of length 1, which is why highlight_cell fails (no 5th index to reference). That observation is what led me to believe knitr was involved in the issue

kyleam commented 8 months ago

what param_str is equal to before and after line 273?

before

Browse[2]> param_str
 [1] "|parameter_names |estimate |stderr   |shrinkage |" "|:---------------|:--------|:--------|:---------|"
 [3] "|THETA1          |3.30     |0.0327   |          |" "|THETA2          |3.25     |0.0287   |          |"
 [5] "|THETA3          |-0.612   |0.00954  |          |" "|THETA4          |-0.208   |0.00832  |          |"
 [7] "|THETA5          |0.737    |0.0397   |          |" "|THETA6          |1.14     |0.0359   |          |"
 [9] "|THETA7          |0.335    |0.0115   |          |" "|THETA8          |0.192    |0.0104   |          |"
[11] "|THETA9          |0.692    |0.0108   |          |" "|THETA10         |2.30     |0.00873  |          |"
[13] "|THETA11         |0.0992   |0.00277  |          |" "|OMEGA(1,1)      |0.0104   |0.000970 |7.31      |"
[15] "|OMEGA(2,2)      |0.00828  |0.00136  |33.7      |" "|OMEGA(3,3)      |0.0131   |0.00324  |40.6      |"
[17] "|OMEGA(4,4)      |0.0110   |0.00204  |27.8      |"

after

Browse[2]> param_str
 [1] "|parameter_names |estimate |stderr   |shrinkage |"
 [2] "|:---------------|:--------|:--------|:---------|"
 [3] "|THETA1          |3.30     |0.0327   |          |"
 [4] "|THETA2          |3.25     |0.0287   |          |"
 [5] "|THETA3          |-0.612   |0.00954  |          |"
 [6] "|THETA4          |-0.208   |0.00832  |          |"
 [7] "|THETA5          |0.737    |0.0397   |          |"
 [8] "|THETA6          |1.14     |0.0359   |          |"
 [9] "|THETA7          |0.335    |0.0115   |          |"
[10] "|THETA8          |0.192    |0.0104   |          |"
[11] "|THETA9          |0.692    |0.0108   |          |"
[12] "|THETA10         |2.30     |0.00873  |          |"
[13] "|THETA11         |0.0992   |0.00277  |          |"
[14] "|OMEGA(1,1)      |0.0104   |0.000970 |7.31      |"
[15] "|OMEGA(2,2)      |0.00828  |0.00136  |\033[31m33.7\033[39m      |"
[16] "|OMEGA(3,3)      |0.0131   |0.00324  |\033[31m40.6\033[39m      |"
[17] "|OMEGA(4,4)      |0.0110   |0.00204  |27.8      |"
barrettk commented 2 months ago

Going to close this issue for now since it never came up again (I recall deleting kableExtra and everything went back to normal, though I know scientists/data scientists have had that package and bbr installed at once (including me) without running into this issue - so I think it's safe to assume I just got into a weird state when working on the model_tree PR)