Recap of Lab 8

Søren Helweg Dam

Exercises recap

Lab 8 Learning Objectives

  • Prepare a simple R package for distributing documented functions

  • Explain the terms Repository, Dependency, and Namespace

  • Implement testing in an R package

  • Collaboratively work on an R package on GitHub

What is an R package?

  • A shareable collection of documented code and/or data

The package you built

DESCRIPTION

Imports vs Depends

Package: PackageName
Type: Package
Title: Central Dogma
Version: 0.1.0
Description: simple R package that replicates the central dogma of molecular biology.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports: 
    ggplot2,
    stringr
Depends:
    R (>= 4.0)

Errors and challenges

Missing DESCRIPTION

> ?randomDNA
ℹ Rendering development documentation for "randomDNA"
Error in .get_package_metadata(pkgdir) : 
  Files 'DESCRIPTION' and 'DESCRIPTION.in' are missing.
Error in .get_package_metadata(pkgdir) : 
  Files 'DESCRIPTION' and 'DESCRIPTION.in' are missing.

Missing DESCRIPTION

> ?randomDNA
ℹ Rendering development documentation for "randomDNA"
Error in .get_package_metadata(pkgdir) : 
  Files 'DESCRIPTION' and 'DESCRIPTION.in' are missing.
Error in .get_package_metadata(pkgdir) : 
  Files 'DESCRIPTION' and 'DESCRIPTION.in' are missing.


An issue with R4.3. Solution: Build tab > install

The NAMESPACE file

> devtools::document()
ℹ Updating cdogma documentation
ℹ Loading cdogma
Warning message:
Skipping NAMESPACE
✖ It already exists and was not generated by roxygen2.

The NAMESPACE file

> devtools::document()
ℹ Updating cdogma documentation
ℹ Loading cdogma
Warning message:
Skipping NAMESPACE
✖ It already exists and was not generated by roxygen2.


Solution: Delete NAMESPACE file and rerun devtools::document()

The NAMESPACE file

# Generated by roxygen2: do not edit by hand

<<<<<<< HEAD
export(function_x)
=======
export(function_y)
>>>>>>> e34c9e2848142b2afa6394733438e78434483ebc

The NAMESPACE file

# Generated by roxygen2: do not edit by hand

<<<<<<< HEAD
export(function_x)
=======
export(function_y)
>>>>>>> e34c9e2848142b2afa6394733438e78434483ebc


Solution: Fix GitHub conflicts

Failing devtools::check()

❯ checking examples ... ERROR
  Running examples in ‘cdogma-Ex.R’ failed
  The error most likely occurred in:
  
  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: hello
  > ### Title: Hello, World!
  > ### Aliases: hello
  > 
  > ### ** Examples
  > 
  > hello()
  Error in hello() : could not find function "hello"
  Execution halted

Failing devtools::check()

❯ checking examples ... ERROR
  Running examples in ‘cdogma-Ex.R’ failed
  The error most likely occurred in:
  
  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: hello
  > ### Title: Hello, World!
  > ### Aliases: hello
  > 
  > ### ** Examples
  > 
  > hello()
  Error in hello() : could not find function "hello"
  Execution halted


Solution: Delete R/hello.R and man/hello.md

Assignment recap

Group assignment

  • Make an R package that simulate (more or less) the central dogma of molecular biology.
  • Discuss why it is a good idea to limit the number of dependencies your package has. When can’t it be avoided?
  • Discuss the difference between adding an @importFrom package function tag to a function description compared to using package::function().
  • Write a vignette (user guide)

Package names

  • centralDogma / Centraldog / cdogma / centdog / Cdogr
  • enigma
  • molecbio
  • dogmaVis
  • BioFlow
  • BioSeqR
  • gene2protein
  • biocd / AnalysisCD
  • CDXX / dogmaXX / groupXX

Dependencies

  • They increase the size of our package.

  • Can introduce compatibility issues.

  • They increase maintenance.

  • They are rarely completely avoidable.

    • When extending other packages (e.g., analysis tools etc.)
    • Works in an ecosystem (e.g., Tidyverse / Bioconductor / Seurat)
    • ggplot plotting

Namespace

  • Extent your package’s namespace with dependency imports
    • @importFrom package function and @import package
    • Cannot be replaced by package::function
    • What is actually the difference?
  • package::function
    • clutters the code…
    • and can be tiresome if used heavily…
    • but ensure better understanding.