Skip to main content

Building an R Package

  • Chapter
  • First Online:
Book cover Beginning Data Science in R
  • 9823 Accesses

Abstract

You now know how to write functions and create classes in R, but neither functions nor classes is the unit you use for collecting and distributing R code. That unit is the package.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 44.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    man stands for manual and the abbreviation man is a legacy from UNIX.

  2. 2.

    e.g., vignettes/ for documentation vignettes, data/ for data you want to include with your package, and src/ for C/C++ extensions.

  3. 3.

    CRAN is the official depository for R package and the place where the install.packages function finds them.

  4. 4.

    There are a few more fields, such as for linking to external C/C++ code, but these three fields are the most important ones.

  5. 5.

    Strictly speaking, this is not true. You can actually get to internal functions if you use the ::: operator instead of the :: operator. So if function_name is not exported but still implemented in the test package, you can access it with test:::function_name. But you shouldn’t. You should keep your damned dirty paws away from internal functions!

  6. 6.

    It is also used to import selected functions or packages, but using Roxygen’s @import and @importFrom functions are better solutions for that.

  7. 7.

    Except through the ::: operator, of course, but people who use this to access the internals of your package knows – or should know – that they are accessing implementation details that could change in the future so it is their own fault if their code is broken sometime down the line.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Thomas Mailund

About this chapter

Cite this chapter

Mailund, T. (2017). Building an R Package. In: Beginning Data Science in R. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-2671-1_11

Download citation

Publish with us

Policies and ethics