
Guidance for Developers
Source:vignettes/articles/Guidance-for-Developers.Rmd
Guidance-for-Developers.Rmd
At present, this is just a handful of thoughts or points I thought worth recording about the development of nadir.
I think debugging function factories is going to be hard. How to improve the user experience with closures and function factory produced functions? It would be nice if when viewing a traceback the name of a learner like
lnr_glmnet
appeared on the call-stack, but instead the call stack goes fromsuper_learner()
tolearners[[i]]
because the learners are passed in a named list.Something we might be worried about and should be careful of is that formula objects store an environment inside them. A way to see this is to call
f <- y ~ x; str(f)
:
f <- y ~ x
str(f)
#> Class 'formula' language y ~ x
#> ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
attr(f, '.Environment')
#> <environment: R_GlobalEnv>
Some preliminary testing has suggested that replicating a formula many times even when the environment contains large objects does not seem to increase memory usage as if the large objects contained in the environment are being replicated.
On the topic of {pkgdown}
- From my experience, when I started running into issues compiling the
pkgdown site, (errors saying that the .Rd files could not
be parsed), I needed to update the dependencies for
pkgdown. I ran
install.packages("pkgdown", dependencies = TRUE)
and that fixed the issues I was running into towards the start of the pkgdown setup.. - I think to debug rendering the pkgdown website, I
also ended up using the advice here: https://stackoverflow.com/questions/66806694/pkgdown-fails-parsing-rd-files-when-examples-are-added,
namely to make sure I have the development version of
downlit
installed.
library(devtools)
install_github('r-lib/downlit')
- Because the articles for the pkgdown website do take
some time to compile, I find it useful to know we can run each of the
sub-components of
pkgdown::build_site()
individually. See: https://pkgdown.r-lib.org/reference/build_site.html - In order to get the pkgdown website to render the
math properly in the documentation for
nadir::lnr_homoskedastic_density()
I had to follow the advice in here https://github.com/r-lib/pkgdown/issues/2704 from user @louisaslett who said that they needed to include in_pkgdown.yml
manually:
template:
bootstrap: 5
includes:
in_header: |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
For now, the images in the README.Rmd are just embedded manually after having been generated (Feb 27 2025) based on the lack of support for Rmd generated images getting copied to the site docs by pkgdown discussed in this thread https://github.com/r-lib/pkgdown/issues/133 with the advice being to put images in
man/figures/
so that images can also be rendered on CRAN.I have tried following the advice here https://github.com/r-lib/pkgdown/issues/995 to get the articles to be in better ordering, but it didn’t seem to work for me.
Note that because the parallelization demo
vignettes/articles/Running-super_learner-in-Parallel.Rmd
uses the multicore setting, it is necessary to runpkgdown::build_article("articles/Running-super_learner-in-Parallel")
from a terminal and not RStudio.
# library(nadir)