10 biocthis introduction
Instructor: Leo
10.2 biocthis main commands
- https://bioconductor.org/packages/biocthis
pkgdown
documentation website: https://lcolladotor.github.io/biocthis/biocthis::use_bioc_pkg_templates()
documentation: https://lcolladotor.github.io/biocthis/reference/use_bioc_pkg_templates.html
These are the main steps you will need to know to make a Bioconductor package
with biocthis
:
- You first will need to create a package using a command from
usethis
.
- For example:
usethis::create_package("~/Desktop/cshl2024pkg")
- Now that you have a package, we can use
biocthis
to create 4 template R scripts that will guide you and help you make the full structure for a Bioconductor R package.
- On your new R package (
cshl2024pkg
), we can now usebiocthis::use_bioc_pkg_templates()
.
In part these commands were born out of my own self interest to make it easier to make new packages instead of copy-pasting the contents of an older one, then manually adjusting all the pieces for a new package. See https://lcolladotor.github.io/pkgs/ for the list of all the R packages I’ve been involved in.
10.3 Live demo
Here is the live demo result https://github.com/lcolladotor/cshl2024pkg/ with its companion documentation website at https://lcolladotor.github.io/cshl2024pkg/. You might also want to check the 2023 version at https://github.com/lcolladotor/cshl2024pkg/.
Check the git commit history at https://github.com/lcolladotor/cshl2024pkg/commits/devel and the GitHub Actions history at https://github.com/lcolladotor/cshl2024pkg/actions. We can see at https://app.codecov.io/gh/lcolladotor/cshl2024pkg the code coverage results for this demonstration package.
10.3.1 Example function
Let’s have a function to work with: weekday_praise()
.
weekday_praise <- function(date = Sys.Date()) {
date <- as.Date(date)
date_weekday <- weekdays(date)
paste0(date_weekday, ": ", praise::praise())
}
weekday_praise()
#> [1] "Tuesday: You are perfect!"
Here’s the full code for the function and its documentation.
#' Praise a weekday
#'
#' Given a date, figure out which weekday it was, then write a positive
#' message.
#'
#' @param date A `base::Date` object or a `character()` in a format that can be
#' converted to a `base::Date` object with `base::as.Date()`.
#'
#' @importFrom praise praise
#' @export
#' @examples
#'
#' ## Praise the current weekday
#' weekday_praise()
#'
#' ## Praise the date we started teaching
#' weekday_praise("2024-06-09")
#'
#' ## Praise the current weekday in a reproducible way
#' set.seed(20240610)
#' weekday_praise()
#'
#' ## Verify that it's reproducible
#' set.seed(20240610)
#' weekday_praise()
weekday_praise <- function(date = Sys.Date()) {
date <- as.Date(date)
date_weekday <- weekdays(date)
paste0(date_weekday, ": ", praise::praise())
}
Here’s a test for our function too.
library("testthat")
#>
#> Attaching package: 'testthat'
#> The following objects are masked from 'package:rlang':
#>
#> is_false, is_null, is_true
#> The following object is masked from 'package:Hmisc':
#>
#> describe
## Verify that we get the result we wanted
set.seed(20240610)
expect_equal(weekday_praise("2024-06-09"), "Sunday: You are wondrous!")
## Verify that we get an error if the input is not correct
expect_error(weekday_praise("240609"))
## Should work for a vector input
expect_equal(length(weekday_praise(c("2024-06-09", "2024-06-10"))), 2L)
10.4 Community
For more materials on R/Bioconductor package development check http://contributions.bioconductor.org/.
I’m on a Friday night mood now enjoying @lmwebr’s #OSTA workshop 🔥, feeling grateful 🙏🏽 to everyone who nominated me for the #BioC2021 community award 🥇& celebrating 🍺 https://t.co/2oFLdGO3Uh
— 🇲🇽 Leonardo Collado-Torres (@lcolladotor) August 7, 2021
See you in #BioC2022🤞🏽 @Bioconductor #rstats @CDSBMexico https://t.co/0SGHDfiRCs pic.twitter.com/UmM9nMP2W2
biocthis
is one of the reasons for my 2021 Bioconductor community award :-)
Do you want to play an active role? Join the cloud-working-group
Slack channel.