vignettes/devoptera.Rmd
devoptera.Rmd
Here, we show how devoptera
can be used to greatly
accelerate your R package development workflow.
source_all
Let’s say you have many functions in your R folder and want
to have access to them all without having to write out the
pkg:::internal_func
notation. You can source all the
functions at once by running devoptera::source_all
.
Thus function can also load any R packages you need by supplying the package names to the
devoptera::source_all(packages = c("rlang","data.table"))
## Loading required package: rlang
## Loading required package: data.table
##
## Attaching package: 'data.table'
## The following object is masked from 'package:rlang':
##
## :=
## Sourcing 19 files.
args2vars
As a developer, how often do you find yourself realizing there’s a bug somewhere inside your function. You could:
Strategy 2
: Edit –> Rebuild –>
Repeat: Make a change to the code, rebuild the package, and
rerun the function as a whole. This most closely mimics how it will run
in production, but is extremely slow when iterating this edit-rebuild
process many, many times over.Strategy 2
:Run internal code
line-by-line: Alternatively, you could go within your function,
run one line of code at a time and inspect the variables it produces at
each step. This is much faster than guessing whether your changes fixed
the bug and rebuilding each time to find out whether they worked. But in
order to do this, you first need to initialise each argument in your
function as a global variable so that you can run the code line-by-line.
But your function has many arguments, so now you spend the next
minute(s) tediously making each argument into a variable of the same
name (using the defaults as the assigned values).devoptera::args2vars
automates Strategy 2
by first running source_all
(from previous example) and
then automatically assigning each of your function’s arguments as global
variables in your R environment. Voila! No more tedious argument
defining, allowing you to rapidly debug your code before going to
rebuild the entire package.
Here we define an arbitrary function with 3 arguments. If your function is already in one of your source files (i.e. a .R file within the R/ subfolder), you can skip this step.
Now we will convert all the default arguments of myfunc
to global variables. It also returns a named list with each variable’s
assigned value.
args <- devoptera::args2vars(myfunc)
## Sourcing 19 files.
## Using input function.
## Assigning '...' to 'NULL'
## Assigning arguments of function: myfunc
## Assigning global ->> a
## Assigning global ->> b
## Reassigning global ->> c
args
## $a
## [1] 1
##
## $b
## [1] 2
##
## $c
## [1] 3
After debugging your code, you can now proceed to the next steps.
Remove all variables using devoptera::rma()
, or by
clicking the little broom :broom: in the upper right of your
Environment
panel in RStudio.
This is important as it will ensure that the names of
functions/variables in your global environment (created with
source_all
/args2vars
) don’t override the
functions/variables within your reinstalled package (in the next
step).
devoptera::rma()
(Re)install your package with devoptera::install
(imported directly from devtools::install
), or by clicking
the Install
button within the Build
panel in
RStudio.
This function is equivalent to the keystrokes
CMD
+SHIFT
+B
within RStudio.
install()
Now you can recheck your package as usual to make sure everything runs as expected.
This check
function is directly imported from
r
BiocStyle::CRANpkg(‘devtools’)`.
This function is equivalent to the keystrokes
CMD
+SHIFT
+E
within RStudio.
check()
This BiocCheck
function is directly imported from
r
Biocpkg::CRANpkg(‘BiocCheck’)`.
BiocCheck()
If you still run into some bugs or unexpected behaviour, don’t worry! You can still easily go back and repeat this process until everything is working smoothly.
Restarting your R session can be helpful or necessary in a variety of situations. Not only does it clear your variables, it unloads all packages which is necessary when you want to use a package you just installed a new version of.
This function is equivalent to the keystrokes
CMD
+SHIFT
+0
within RStudio.
devoptera::restart()
It is best practice to always include your R Session Info in any Rmarkdown report or vignette. It contains information about which OS, R version, and R package versions you generated the report with.
devoptera::session_info
provides a collapsible version
of the Session Info, which can be helpful when Session Info is
particularly long.
devoptera::session_info()
## ─ Session info ───────────────────────────────────────────────────────────────
## setting value
## version R Under development (unstable) (2024-03-28 r86224)
## os Ubuntu 22.04.4 LTS
## system x86_64, linux-gnu
## ui X11
## language en
## collate en_US.UTF-8
## ctype en_US.UTF-8
## tz UTC
## date 2024-04-01
## pandoc 3.1.1 @ /usr/local/bin/ (via rmarkdown)
##
## ─ Packages ───────────────────────────────────────────────────────────────────
## package * version date (UTC) lib source
## Biobase 2.63.1 2024-03-29 [1] Bioconductor 3.19 (R 4.5.0)
## BiocBaseUtils 1.5.1 2024-03-08 [1] Bioconductor 3.19 (R 4.5.0)
## BiocCheck 1.39.27 2024-03-25 [1] Bioconductor 3.19 (R 4.5.0)
## BiocFileCache 2.11.2 2024-03-27 [1] Bioconductor 3.19 (R 4.5.0)
## BiocGenerics 0.49.1 2023-11-01 [1] Bioconductor
## BiocManager 1.30.22 2023-08-08 [1] CRAN (R 4.5.0)
## BiocStyle * 2.31.0 2023-10-24 [1] Bioconductor
## biocViews 1.71.1 2023-10-25 [1] Bioconductor
## bit 4.0.5 2022-11-15 [1] CRAN (R 4.4.0)
## bit64 4.0.5 2020-08-30 [1] CRAN (R 4.4.0)
## bitops 1.0-7 2021-04-24 [1] CRAN (R 4.4.0)
## blob 1.2.4 2023-03-17 [1] CRAN (R 4.4.0)
## bookdown 0.38 2024-03-04 [1] CRAN (R 4.5.0)
## bslib 0.7.0 2024-03-29 [2] CRAN (R 4.5.0)
## cachem 1.0.8 2023-05-01 [2] CRAN (R 4.5.0)
## cli 3.6.2 2023-12-11 [2] CRAN (R 4.5.0)
## codetools 0.2-19 2023-02-01 [3] CRAN (R 4.5.0)
## curl 5.2.1 2024-03-01 [2] CRAN (R 4.5.0)
## data.table * 1.15.4 2024-03-30 [1] CRAN (R 4.5.0)
## DBI 1.2.2 2024-02-16 [1] CRAN (R 4.5.0)
## dbplyr 2.5.0 2024-03-19 [1] CRAN (R 4.5.0)
## desc 1.4.3 2023-12-10 [2] CRAN (R 4.5.0)
## devoptera * 0.99.1 2024-04-01 [1] Bioconductor
## devtools 2.4.5 2022-10-11 [2] CRAN (R 4.5.0)
## digest 0.6.35 2024-03-11 [2] CRAN (R 4.5.0)
## dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.4.0)
## ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.5.0)
## evaluate 0.23 2023-11-01 [2] CRAN (R 4.5.0)
## fansi 1.0.6 2023-12-08 [2] CRAN (R 4.5.0)
## fastmap 1.1.1 2023-02-24 [2] CRAN (R 4.5.0)
## filelock 1.0.3 2023-12-11 [1] CRAN (R 4.4.0)
## fs 1.6.3 2023-07-20 [2] CRAN (R 4.5.0)
## generics 0.1.3 2022-07-05 [1] CRAN (R 4.4.0)
## glue 1.7.0 2024-01-09 [2] CRAN (R 4.5.0)
## graph 1.81.0 2023-10-24 [1] Bioconductor
## here 1.0.1 2020-12-13 [1] CRAN (R 4.4.0)
## htmltools 0.5.8 2024-03-25 [2] CRAN (R 4.5.0)
## htmlwidgets 1.6.4 2023-12-06 [2] CRAN (R 4.5.0)
## httpuv 1.6.15 2024-03-26 [2] CRAN (R 4.5.0)
## httr 1.4.7 2023-08-15 [2] CRAN (R 4.5.0)
## httr2 1.0.0 2023-11-14 [2] CRAN (R 4.5.0)
## jquerylib 0.1.4 2021-04-26 [2] CRAN (R 4.5.0)
## jsonlite 1.8.8 2023-12-04 [2] CRAN (R 4.5.0)
## knitr 1.45 2023-10-30 [2] CRAN (R 4.5.0)
## later 1.3.2 2023-12-06 [2] CRAN (R 4.5.0)
## lifecycle 1.0.4 2023-11-07 [2] CRAN (R 4.5.0)
## magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.5.0)
## memoise 2.0.1 2021-11-26 [2] CRAN (R 4.5.0)
## mime 0.12 2021-09-28 [2] CRAN (R 4.5.0)
## miniUI 0.1.1.1 2018-05-18 [2] CRAN (R 4.5.0)
## pillar 1.9.0 2023-03-22 [2] CRAN (R 4.5.0)
## pkgbuild 1.4.4 2024-03-17 [2] CRAN (R 4.5.0)
## pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.5.0)
## pkgdown 2.0.7 2022-12-14 [1] CRAN (R 4.5.0)
## pkgload 1.3.4 2024-01-16 [2] CRAN (R 4.5.0)
## profvis 0.3.8 2023-05-02 [2] CRAN (R 4.5.0)
## promises 1.2.1 2023-08-10 [2] CRAN (R 4.5.0)
## purrr 1.0.2 2023-08-10 [2] CRAN (R 4.5.0)
## R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.4.0)
## R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.4.0)
## R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.4.0)
## R6 2.5.1 2021-08-19 [2] CRAN (R 4.5.0)
## ragg 1.3.0 2024-03-13 [2] CRAN (R 4.5.0)
## rappdirs 0.3.3 2021-01-31 [2] CRAN (R 4.5.0)
## RBGL 1.79.0 2023-10-24 [1] Bioconductor
## Rcpp 1.0.12 2024-01-09 [2] CRAN (R 4.5.0)
## RCurl 1.98-1.14 2024-01-09 [1] CRAN (R 4.4.0)
## remotes 2.5.0.9000 2024-04-01 [1] Github (r-lib/remotes@ac483e7)
## rlang * 1.1.3 2024-01-10 [2] CRAN (R 4.5.0)
## rmarkdown 2.26 2024-03-05 [1] CRAN (R 4.5.0)
## rprojroot 2.0.4 2023-11-05 [2] CRAN (R 4.5.0)
## RSQLite 2.3.6 2024-03-31 [1] CRAN (R 4.5.0)
## rstudioapi 0.16.0 2024-03-24 [2] CRAN (R 4.5.0)
## RUnit 0.4.33 2024-02-22 [1] CRAN (R 4.5.0)
## sass 0.4.9 2024-03-15 [2] CRAN (R 4.5.0)
## sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.5.0)
## shiny 1.8.1 2024-03-26 [2] CRAN (R 4.5.0)
## stringdist 0.9.12 2023-11-28 [1] CRAN (R 4.4.0)
## stringi 1.8.3 2023-12-11 [2] CRAN (R 4.5.0)
## stringr 1.5.1 2023-11-14 [2] CRAN (R 4.5.0)
## systemfonts 1.0.6 2024-03-07 [2] CRAN (R 4.5.0)
## textshaping 0.3.7 2023-10-09 [2] CRAN (R 4.5.0)
## tibble 3.2.1 2023-03-20 [2] CRAN (R 4.5.0)
## tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.5.0)
## urlchecker 1.0.1 2021-11-30 [2] CRAN (R 4.5.0)
## usethis 2.2.3 2024-02-19 [2] CRAN (R 4.5.0)
## utf8 1.2.4 2023-10-22 [2] CRAN (R 4.5.0)
## vctrs 0.6.5 2023-12-01 [2] CRAN (R 4.5.0)
## xfun 0.43 2024-03-25 [2] CRAN (R 4.5.0)
## XML 3.99-0.16.1 2024-01-22 [1] CRAN (R 4.4.0)
## xtable 1.8-4 2019-04-21 [2] CRAN (R 4.5.0)
## yaml 2.3.8 2023-12-11 [2] CRAN (R 4.5.0)
##
## [1] /__w/_temp/Library
## [2] /usr/local/lib/R/site-library
## [3] /usr/local/lib/R/library
##
## ──────────────────────────────────────────────────────────────────────────────