ETC5523: Communicating with Data

R Packages and documentation

Lecturer: Michael Lydeamore

Department of Econometrics and Business Statistics



Aim

  • Document your functions
  • Create vignettes for your package
  • Implement testing framework for your package
  • Distribute your package

Why

  • Documentation informs users of how to use your package
  • Adopting best practice development workflow will make package development easier
  • Testing can increase the trust worthiness of the package
  • Distributing your package is needed for adoption of your package by others

Let’s make a package

This is a taste of ETC4500/5450 (Advanced R Programming). We will learn the bare minimum required to get to documentation.

Communicating about your R package

  • What is the goal of the package?
  • What does your function(s) do?
  • How do we use it?
  • Why should we use it?
  • Where do we find and install it?

Documentation is vital

ausbirthplace package

It’s never been easier to make a package. The usethis package can do all of the heavy lifting for us

Tip

This means we can easily make packages that might only be just “for us”

This package is for teaching demo only

usethis::create_package("ausbirthplace")

will set up the directory structure we need for a package.

Package directory structure

- R/
- .Rproj.user/
- packagename.Rproj
- .gitignore
- .Rbuildignore
- DESCRIPTION
- NAMESPACE

Functions for the package

Anything in the R/ folder will be loaded by the package.

Tip

If you want the user to use it, it needs to be in R

Functions go in R/

Data for the package

Your package could load in some data (like palmerpenguins::penguins for example).

Exported data objects go in data, and the code/files to produce them goes in data-raw

usethis::use_data_raw('census-birthplace')

This will create two new folders: data and data-raw.

Loading and testing

devtools gives us an easy pipeline for loading and testing our package without having to install it

devtools::load_all()
censusbirthplace

You can also use the default hotkey Ctrl+Shift+L to load.

You should reload often - try to avoid manually sourcing files unless you have to!

NAMESPACE, DESCRIPTION, README

There are three other files that are generated in a package:

  • NAMESPACE: Machine generated, list of objects that are ‘exported’ (available to users) of the package
  • DESCRIPTION: Contains metadata about the package which we need to complete
  • README: Top-level description of your package that people will see before they install the package

README

Hadley gives a good template for a README:

  1. A paragraph describing the purpose of the package
  2. An example that shows how to use the package to solve a simple problem
  3. Installation instructions that you can copy/paste straight into R
  4. An overview of the main components of the package.

We can set up the README using

usethis::use_readme_rmd()

and then edit to suit your package.

DESCRIPTION

usethis sets up a template DESCRIPTION file:

Package: mypackage
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R: 
    person("First", "Last", , "first.last@example.com", role = c("aut", "cre"),
           comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
    license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2

You should edit this for your package.

Using other packages

Inevitably, you’ll want to use a function from another package. Again there’s a usethis function for that too:

usethis::use_package("ggplot2")

You still have to reference package namespaces using ::: or @importFrom (more on this one later).

For example:

plot_census_data <- function() {
  censusdata |>
    ggplot2::ggplot(ggplot2::aes(x=count, y=birth)) +
    ggplot2::geom_col() +
    ggplot2::labs(x="Number of residents", y="Country of birth")
}

Code commenting

Comments in code are communication. There’s no need to re-state very clear code, but if you are doing anything even mildly complicated, changes are you won’t be able to understand the code quickly.

Example:

palmerpenguins::penguins |>
  dplyr::select(species, bill_depth_mm, bill_length_mm, flipper_length_mm, island) |>
  tidyr::pivot_longer(!c(species, island)) |>
  dplyr::group_by(species, island) |>
  dplyr::summarise(means = mean(value, na.rm=T)) |>
  tidyr::pivot_wider(names_from = species, values_from = means)

Code commenting

Comments in code are communication. There’s no need to re-state very clear code, but if you are doing anything even mildly complicated, changes are you won’t be able to understand the code quickly.

Example:

palmerpenguins::penguins |>
  dplyr::select(species, bill_depth_mm, bill_length_mm, flipper_length_mm, island) |>
  # Go from wide to long, keeping species and island as keys
  tidyr::pivot_longer(!c(species, island)) |>
  dplyr::group_by(species, island) |>
  # Means of all measurements by species and island (drop NAs)
  dplyr::summarise(means = mean(value, na.rm=T)) |>
  # Back to wide for with island as rows and species as columns
  tidyr::pivot_wider(names_from = species, values_from = means)

Code commenting

It’s hard to put in too many comments, so feel free to use them liberally.

But, make sure you apply the principles of communication to your comments to: conciseness and clarity are key

Function documentation

When we don’t know how to use a function, we look up the function documentation by typing ?group_by.

But where does this documentation come from?

R gives a standard way of documenting packages: you write .Rd files in the man/ directory. These files use a custom syntax, which is very similar to LaTeX.

This separates code from comments, making it easy to forget to update a function’s documentation if you change the function. roxygen2 puts the documentation with your code, and generates .Rd files.

roxygen2 skeleton

#' Function title
#' 
#' Function description
#' 
#' @param param_name Parameter description
#' @return What does the function return?
#' @examples
#' R code for examples goes here
myfunction <- function(param_name) {
  print(param_name)
}

Applying to our function from earlier

plot_census_data <- function() {
  censusdata |>
    ggplot2::ggplot(ggplot2::aes(x=count, y=birth)) +
    ggplot2::geom_col() +
    ggplot2::labs(x="Number of residents", y="Country of birth")
}

Applying to our function from earlier

#' Histogram of Australian census data
#' 
#' Plots a histogram of the Australian census data showing the
#' country of birth of residents of Australia from the 2016
#' and 2021 census
#' @return `ggplot2` plot with the histogram geom
#' @examples
#' plot_census_data()
#' 
#' @export
plot_census_data <- function() {
  censusdata |>
    ggplot2::ggplot(ggplot2::aes(x=count, y=birth)) +
    ggplot2::geom_col() +
    ggplot2::labs(x="Number of residents", y="Country of birth")
}

Generating the .Rd file

Just writing roxygen2 doesn’t generate the man files. To get these, we have to run

devtools::document()

If you are in RStudio, you can press ctrl+shift+d

Important

For a function to be accessible by installing your package, you need to include the @export tag!

Data documentation

Just like functions, we have to document our data. You can put this anywhere (after all, there is no function that generates our data), but the convention is in R/data.R.

For our data,

#' Number of Australian residents by country of birth from the 2016 and 2021 census
#' 
#' @format ## 'censusdata'
#' A data frame with 105 rows and 4 columns
#' \describe{
#'   \item{birth}{Country of birth}
#'   \item{count}{Number of residents from that birth country}
#'   \item{percentage}{Percentage of residents from that birth country}
#'   \item{census}{Year of census (either 2016 or 2021)}
#' }
#' @source <https://www.abs.gov.au/websitedbs/censushome.nsf/home/2016>

Vignettes

Documentation is great to look at something specific (like a function).

What if you’ve just installed a package and would like to know how to use it?

Enter the Vignette

Vignettes

Vignettes are “how-to” guides to packages. Perhaps they document a specific workflow, or how to solve a specific problem.

Check out the dplyr vignettes

Writing vignettes

When you’re writing the vignette, take the position of the reader (not the developer). Your audience is someone who might have never used your package before.

This is hard - you know a lot about your package - so try some techniques to help:

  • Ask a friend to follow the vignette
  • Give a presentation and ask people to stop you anytime they don’t understand something

Writing a vignette can also help you improve your code. If you find yourself saying “Oh this is hard to code here” then think about going back and changing the code itself.

Vignettes: How to

usethis::use_vignette("packagename")

This creates a .Rmd file (no quarto yet) with some template options filled in

Demo

Extension: Custom print method (not assessable)

What happens when you type print(object) in R?

  • print is a function
print
function (x, ...) 
UseMethod("print")
<bytecode: 0x562960af31a0>
<environment: namespace:base>

Methods and OOP in R

This is an example of an S3 function.

We can’t cover precisely what this means here (come back in ARP for that), but we can think of this as

a different print function is called depending on what object looks like.

Which method is chosen is based on the class of object.

Methods and OOP in R

fit <- lm(bill_length_mm ~ bill_depth_mm, data = palmerpenguins::penguins)
class(fit)
[1] "lm"
getAnywhere(print.lm)
A single object matching 'print.lm' was found
It was found in the following places
  registered S3 method for print from namespace stats
  namespace:stats
with value

function (x, digits = max(3L, getOption("digits") - 3L), ...) 
{
    cat("\nCall:\n", paste(deparse(x$call), sep = "\n", collapse = "\n"), 
        "\n\n", sep = "")
    if (length(coef(x))) {
        cat("Coefficients:\n")
        print.default(format(coef(x), digits = digits), print.gap = 2L, 
            quote = FALSE)
    }
    else cat("No coefficients\n")
    cat("\n")
    invisible(x)
}
<bytecode: 0x5629610ef0d0>
<environment: namespace:stats>

Methods and OOP in R

You might notice that class(fit) is just a vector. We can add our own class to any object we like.

class(fit) <- "myclass"

print.myclass <- function(object) {
  "This is my special class"
}

print(fit)
[1] "This is my special class"

Custom print methods

You have full control over the print method for your class, so you know exactly what the object should look like.

print methods are communication too! Which of these is better?

print(fit)

Call:
lm(formula = bill_length_mm ~ bill_depth_mm, data = palmerpenguins::penguins)

Coefficients:
  (Intercept)  bill_depth_mm  
      55.0674        -0.6498  
print.default(fit)
$coefficients
  (Intercept) bill_depth_mm 
   55.0673698    -0.6498356 

$residuals
           1            2            3            5            6            7 
 -3.81544474  -4.26023098  -3.07032964  -5.82554341  -2.38075717  -4.60029675 
           8            9           10           11           12           13 
 -3.13059274  -9.20534608   0.05930860  -6.15518164  -6.02521453  -2.53026386 
          14           15           16           17           18           19 
 -2.69085584  -6.75583939  -6.90029675  -4.02049407   0.88422638  -8.71039541 
          20           21           22           23           24           25 
  4.90409483  -5.37537897  -5.21544474  -6.69052696  -5.10534608  -5.09019809 
          26           27           28           29           30           31 
 -7.48547763  -2.38042830  -2.93531319  -5.08042830  -2.28547763  -4.71511587 
          32           33           34           35           36           37 
 -6.10534608  -4.00029675  -1.88547763  -7.62016520  -2.15583939  -3.27065851 
          38           39           40           41           42           43 
 -0.84541186  -4.92554341  -2.85551052  -6.87032964  -2.31039541  -7.04541186 
          44           45           46           47           48           49 
  1.83439082  -7.08514876  -3.25046119  -1.62049407  -5.28547763  -7.43531319 
          50           51           52           53           54           55 
  1.00914416  -3.96528031  -2.68547763  -8.43531319  -0.39557629  -8.80534608 
          56           57           58           59           60           61 
 -1.58042830  -4.69524742  -2.25046119  -7.78009943  -5.05551052  -8.38514876 
          62           63           64           65           66           67 
 -0.05583939  -6.42016520  -2.14036252  -7.55518164  -1.77032964  -9.04003365 
          68           69           70           71           72           73 
 -1.55551052  -8.38009943  -0.66055985  -9.22049407  -3.41039541  -4.29019809 
          74           75           76           77           78           79 
  3.01452237  -8.19524742  -0.24541186  -3.25013231  -5.26055985  -8.40501721 
          80           81           82           83           84           85 
 -0.55551052  -9.29019809  -0.73026386  -6.15046119  -7.36055985  -6.20029675 
          86           87           88           89           90           91 
 -0.57570784  -6.09557629  -6.08042830  -4.29052696  -3.95046119  -7.67032964 
          92           93           94           95           96           97 
 -2.20534608  -9.95518164  -3.70534608  -7.62521453  -1.98547763  -4.88042830 
          98           99          100          101          102          103 
 -2.74541186 -11.50501721   0.15458814  -8.43531319  -1.07065851  -6.97000076 
         104          105          106          107          108          109 
 -4.27065851  -5.08042830  -3.08547763  -5.29019809  -3.87065851  -5.92016520 
         110          111          112          113          114          115 
  0.47950593  -6.24508298   3.72429216  -3.86528031  -0.19557629  -2.01577362 
         116          117          118          119          120          121 
 -0.47537897  -5.42016520  -4.44574073  -8.32016520  -1.88042830  -7.69019809 
         122          123          124          125          126          127 
 -4.50062562  -3.82016520  -1.64541186  -9.53498432  -2.12049407  -4.83026386 
         128          129          130          131          132          133 
 -1.67537897  -4.95518164   0.72967036  -4.93531319   0.50947304  -6.24541186 
         134          135          136          137          138          139 
 -5.54541186  -5.53026386  -2.59524742  -8.09524742  -1.80567496  -7.34508298 
         140          141          142          143          144          145 
 -3.73531319  -3.75518164  -3.29019809 -12.89491855  -3.32016520  -6.85013231 
         146          147          148          149          150          151 
 -3.91544474  -3.78042830  -6.51039541  -7.50029675  -5.50534608  -7.95518164 
         152          153          154          155          156          157 
 -1.54541186  -0.38954034   5.52494991   2.79531167   4.81013079   1.95524589 
         158          159          160          161          162          163 
  0.20541033  -0.17977055   1.57511434  -3.05957323   1.74009790  -5.26462256 
         164          165          166          167          168          169 
  4.39498279  -0.66462256   2.82022945   0.22022945   4.43504857  -4.29458967 
         170          171          172          173          174          175 
  4.01013079   0.55524589   3.44514723   4.42527878  -0.54475411   0.85524589 
         176          177          178          179          180          181 
  1.50003212  -3.65452390   0.84514723  -1.27472122   2.48016367   2.42527878 
         182          183          184          185          186          187 
  4.87511434   2.17511434  -3.03970478  -0.54475411  15.57983480   3.65019656 
         188          189          190          191          192          193 
  3.92494991  -3.56462256   0.57478547  -2.22960611   3.83504857  -3.46462256 
         194          195          196          197          198          199 
  4.92999924  -0.86462256   4.28016367   5.76501568  -2.43465545  -0.53465545 
         200          201          202          203          204          205 
  5.76501568  -1.52455678   0.40003212   0.76029522   2.59531167  -0.60973766 
         206          207          208          209          210          211 
  4.78016367   0.79026234  -0.05990210  -2.23465545   0.18016367  -2.44475411 
         212          213          214          215          216          217 
  5.27511434  -0.79963900   0.81518012  -0.33465545   9.43504857  -0.03970478 
         218          219          220          221          222          223 
  5.64986769   0.49026234   4.95996635  -2.33970478   5.38016367   2.38016367 
         224          225          226          227          228          229 
  1.47006501   3.27006501   1.05019656   1.08016367   3.92999924   1.66029522 
         230          231          232          233          234          235 
  6.62494991  -0.89963900   0.78993346   3.45524589   7.57006501   1.82022945 
         236          237          238          239          240          241 
  5.26501568  -1.19963900   6.97478547  -2.30973766   5.46029522   1.53032811 
         242          243          244          245          246          247 
  8.07983480   2.18016367   8.24481836  -0.14475411   4.89498279  -1.01478700 
         248          249          250          251          252          253 
  5.93504857   4.60003212   1.32022945   2.69026234   6.75491702   3.18016367 
         254          255          256          257          258          259 
 11.87983480   2.20508145   3.78016367   1.20036100   2.19498279  -3.81478700 
         260          261          262          263          264          265 
  8.60003212  -2.66967189   2.84514723   5.31013079   5.06501568  -1.68986921 
         266          267          268          269          270          271 
  7.02494991   0.29531167  10.42999924  -0.36495143   4.25996635   1.03537744 
         273          274          275          276          277          278 
  1.02527878   5.53504857  -0.24980344   5.29498279   3.06468681   7.60442371 
         279          280          281          282          283          284 
  8.70947304   2.48455526  10.49937438   1.69970325   2.85963748   8.05963748 
         285          286          287          288          289          290 
  3.21452237   9.16435793   3.09970325   9.82429216   3.17478547   8.69465392 
         291          292          293          294          295          296 
  1.94481836   8.16940726   8.22934149  14.49970325   3.41957170   5.95963748 
         297          298          299          300          301          302 
 -1.42521453   4.80475258  -1.08009943   8.13944015   3.26468681   9.27950593 
         303          304          305          306          307          308 
  7.38960459   6.77950593   2.89970325  10.72934149  -3.38009943  12.64920994 
         309          310          311          312          313          314 
 -1.71511587   8.14953881   6.71957170   3.34986769   4.42462103  10.38422638 
         315          316          317          318          319          320 
  2.61990057  11.36435793   6.60442371   2.50475258   8.24448948   1.47983480 
         321          322          323          324          325          326 
  7.46468681   7.75458814   6.66468681   6.66940726   8.58455526   5.97478547 
         327          328          329          330          331          332 
  3.68993346   8.67950593   1.87478547   8.43439082  -1.32521453   9.34953881 
         333          334          335          336          337          338 
  0.91990057   7.16435793   7.34953881   3.13944015   9.50442371   2.45491702 
         339          340          341          342          343          344 
  1.67983480  13.59937438   0.19465392   6.35963748   8.07950593   7.28455526 

$effects
  (Intercept) bill_depth_mm                                           
-812.25887774   23.69748615   -2.78924194   -5.40023118   -1.81122041 
                                                                      
  -4.34139744   -2.67199792   -8.91316419    0.58446858   -5.97394169 
                                                                      
  -5.82178619   -2.29355294   -2.05475391   -6.13083166   -6.64139744 
                                                                      
  -3.62846443    1.46485734   -8.38493093    5.57347934   -5.06100868 
                                                                      
  -4.85669768   -6.27630893   -4.81316419   -4.89786394   -7.10454218 
                                                                      
  -2.03277543   -2.66531969   -4.73277543   -1.90454218   -4.57825270 
                                                                      
  -5.81316419   -3.74139744   -1.50454218   -7.45001945   -1.53083166 
                                                                      
  -2.76768692   -0.50885318   -4.50023118   -2.45238668   -6.58924194 
                                                                      
  -1.98493093   -6.70885318    2.30407983   -6.92609720   -2.88061993 
                                                                      
  -1.22846443   -4.90454218   -7.16531969    1.64524609   -3.71747519 
                                                                      
  -2.30454218   -8.16531969    0.05192433   -8.51316419   -1.23277543 
                                                                      
  -4.46963069   -1.88061993   -7.65433045   -4.65238668   -8.22609720 
                                                                      
   0.56916834   -6.25001945   -1.83708644   -7.37394169   -1.48924194 
                                                                      
  -8.95864145   -1.15238668   -8.25433045   -0.22415342   -8.82846443 
                                                                      
  -3.08493093   -4.09786394    3.39545782   -7.96963069    0.09114682 
                                                                      
  -3.10217495   -4.82415342   -8.33471920   -0.15238668   -9.09786394 
                                                                      
  -0.49355294   -5.78061993   -6.92415342   -5.94139744   -0.03945367 
                                                                      
  -5.64807567   -5.73277543   -3.87630893   -3.58061993   -7.38924194 
                                                                      
  -1.91316419   -9.77394169   -3.41316419   -7.42178619   -1.60454218 
                                                                      
  -4.53277543   -2.40885318  -11.43471920    0.49114682   -8.16531969 
                                                                      
  -0.56768692   -6.91079695   -3.76768692   -4.73277543   -2.70454218 
                                                                      
  -5.09786394   -3.36768692   -5.75001945    0.87153557   -6.13040820 
                                                                      
   4.26054633   -3.61747519    0.25192433   -1.43514266   -0.16100868 
                                                                      
  -5.25001945   -3.88729816   -8.15001945   -1.53277543   -7.49786394 
                                                                      
  -4.01984242   -3.65001945   -1.30885318   -9.48687471   -1.72846443 
                                                                      
  -4.59355294   -1.36100868   -4.77394169    1.01075806   -4.66531969 
                                                                      
   0.92369107   -5.90885318   -5.20885318   -5.29355294   -2.36963069 
                                                                      
  -7.86963069   -1.29160917   -7.23040820   -3.46531969   -3.57394169 
                                                                      
  -3.09786394  -12.89118571   -3.15001945   -6.70217495   -3.55669768 
                                                                      
  -3.43277543   -6.18493093   -7.24139744   -5.21316419   -7.77394169 
                                                                      
  -1.20885318   -0.64097398    5.61743630    2.64372578    4.78058104 
                                                                      
   1.84803678   -0.01274073   -0.27588547    1.55665879   -3.28881848 
                                                                      
   1.73273654   -5.46058522    4.46528080   -0.86058522    2.72411453 
                                                                      
   0.12411453    4.46096979   -4.51274073    3.98058104    0.44803678 
                                                                      
   3.40450329    4.29588128   -0.65196322    0.74803678    1.53704754 
                                                                      
  -3.91705173    0.80450329   -1.40411872    2.42842554    2.29588128 
                                                                      
   4.85665879    2.15665879   -3.18019647   -0.65196322   15.74998055 
                                                                      
   3.57627003    4.01743630   -3.76058522    0.77821381   -2.43666298 
                                                                      
   3.86096979   -3.66058522    4.98920305   -1.06058522    4.22842554 
                                                                      
   5.81312529   -2.60842972   -0.70842972    5.81312529   -1.76489623 
                                                                      
   0.43704754    0.61980353    2.44372578   -0.72804097    4.72842554 
                                                                      
   0.67195903   -0.06726346   -2.40842972    0.12842554   -2.55196322 
                                                                      
   5.25665879   -0.98450747    0.75234779   -0.50842972    9.46096979 
                                                                      
  -0.18019647    5.79782505    0.37195903    5.04135855   -2.48019647 
                                                                      
   5.32842554    2.32842554    1.48489204    3.28489204    0.97627003 
                                                                      
   1.02842554    3.98920305    1.51980353    6.71743630   -1.08450747 
                                                                      
   0.89351405    3.34803678    7.58489204    1.72411453    5.31312529 
                                                                      
  -1.38450747    7.17821381   -2.42804097    5.31980353    1.36764803 
                                                                      
   8.24998055    2.12842554    8.42605831   -0.25196322    4.96528080 
                                                                      
  -1.09980772    5.96096979    4.63704754    1.22411453    2.57195903 
                                                                      
   6.86959180    3.12842554   12.04998055    2.20881429    3.72842554 
                                                                      
   1.01549253    2.26528080   -3.89980772    8.63704754   -2.83235197 
                                                                      
   2.80450329    5.28058104    5.11312529   -1.71941896    7.11743630 
                                                                      
   0.14372578   10.48920305   -0.33903021    4.34135855    0.83941478 
                                                                      
   0.89588128    5.56096979   -0.32372997    5.36528080    3.33468031 
                                                                      
   8.05192433    9.12369107    2.84330232   10.98015758    1.95860256 
                                                                      
   3.16291356    8.36291356    3.59545782    9.65623533    3.35860256 
                                                                      
  10.36054633    3.37821381    8.98683581    2.12605831    8.62800208 
                                                                      
   8.73231308   14.75860256    3.76722457    6.26291356   -1.22178619 
                                                                      
   5.03036931   -0.95433045    8.57584658    3.53468031    9.67153557 
                                                                      
   7.71506907    7.17153557    3.15860256   11.23231308   -3.25433045 
                                                                      
  13.24093509   -1.57825270    8.51938007    7.06722457    3.49782505 
                                                                      
   4.73899132   10.96485734    2.74566955   11.85623533    7.05192433 
                                                                      
   2.73036931    8.64761332    1.64998055    7.73468031    8.09114682 
                                                                      
   6.93468031    7.12800208    8.94330232    6.17821381    3.79351405 
                                                                      
   9.07153557    2.07821381    8.90407983   -1.12178619    9.71938007 
                                                                      
   1.04566955    7.65623533    7.71938007    3.57584658    9.95192433 
                                                                      
   2.56959180    1.84998055   14.08015758    0.48683581    6.66291356 
                            
   8.47153557    7.64330232 

$rank
[1] 2

$fitted.values
       1        2        3        5        6        7        8        9 
42.91544 43.76023 43.37033 42.52554 41.68076 43.50030 42.33059 43.30535 
      10       11       12       13       14       15       16       17 
41.94069 43.95518 43.82521 43.63026 41.29086 41.35584 43.50030 42.72049 
      18       19       20       21       22       23       24       25 
41.61577 43.11040 41.09591 43.17538 42.91544 42.59053 43.30535 43.89020 
      26       27       28       29       30       31       32       33 
42.78548 42.98043 43.43531 42.98043 42.78548 44.21512 43.30535 43.50030 
      34       35       36       37       38       39       40       41 
42.78548 44.02017 41.35584 42.07066 43.04541 42.52554 42.65551 43.37033 
      42       43       44       45       46       47       48       49 
43.11040 43.04541 42.26561 44.08515 42.85046 42.72049 42.78548 43.43531 
      50       51       52       53       54       55       56       57 
41.29086 43.56528 42.78548 43.43531 42.39558 43.30535 42.98043 43.69525 
      58       59       60       61       62       63       64       65 
42.85046 44.28010 42.65551 44.08515 41.35584 44.02017 43.24036 43.95518 
      66       67       68       69       70       71       72       73 
43.37033 44.54003 42.65551 44.28010 42.46056 42.72049 43.11040 43.89020 
      74       75       76       77       78       79       80       81 
42.78548 43.69525 43.04541 44.15013 42.46056 44.60502 42.65551 43.89020 
      82       83       84       85       86       87       88       89 
43.63026 42.85046 42.46056 43.50030 41.87571 42.39558 42.98043 42.59053 
      90       91       92       93       94       95       96       97 
42.85046 43.37033 43.30535 43.95518 43.30535 43.82521 42.78548 42.98043 
      98       99      100      101      102      103      104      105 
43.04541 44.60502 43.04541 43.43531 42.07066 44.67000 42.07066 42.98043 
     106      107      108      109      110      111      112      113 
42.78548 43.89020 42.07066 44.02017 42.72049 44.34508 41.87571 43.56528 
     114      115      116      117      118      119      120      121 
42.39558 41.61577 43.17538 44.02017 41.74574 44.02017 42.98043 43.89020 
     122      123      124      125      126      127      128      129 
42.20063 44.02017 43.04541 44.73498 42.72049 43.63026 43.17538 43.95518 
     130      131      132      133      134      135      136      137 
43.37033 43.43531 42.59053 43.04541 43.04541 43.63026 43.69525 43.69525 
     138      139      140      141      142      143      144      145 
42.00567 44.34508 43.43531 43.95518 43.89020 44.99492 44.02017 44.15013 
     146      147      148      149      150      151      152      153 
42.91544 42.98043 43.11040 43.50030 43.30535 43.95518 43.04541 46.48954 
     154      155      156      157      158      159      160      161 
44.47505 45.90469 45.18987 45.64475 46.29459 45.57977 45.12489 46.35957 
     162      163      164      165      166      167      168      169 
45.05990 46.16462 44.60502 46.16462 45.57977 45.57977 44.86495 46.29459 
     170      171      172      173      174      175      176      177 
45.18987 45.64475 45.25485 45.77472 45.64475 45.64475 44.79997 46.55452 
     178      179      180      181      182      183      184      185 
45.25485 45.77472 45.31984 45.77472 45.12489 45.12489 45.83970 45.64475 
     186      187      188      189      190      191      192      193 
44.02017 45.44980 44.47505 46.16462 43.82521 46.22961 44.86495 46.16462 
     194      195      196      197      198      199      200      201 
44.67000 46.16462 45.31984 44.73498 46.03466 46.03466 44.73498 46.42456 
     202      203      204      205      206      207      208      209 
44.79997 45.83970 45.90469 45.70974 45.31984 45.70974 45.05990 46.03466 
     210      211      212      213      214      215      216      217 
45.31984 45.64475 45.12489 46.09964 45.38482 46.03466 44.86495 45.83970 
     218      219      220      221      222      223      224      225 
44.15013 45.70974 44.54003 45.83970 45.31984 45.31984 44.92993 44.92993 
     226      227      228      229      230      231      232      233 
45.44980 45.31984 44.67000 45.83970 44.47505 46.09964 44.41007 45.64475 
     234      235      236      237      238      239      240      241 
44.92993 45.57977 44.73498 46.09964 43.82521 45.70974 45.83970 45.96967 
     242      243      244      245      246      247      248      249 
44.02017 45.31984 43.95518 45.64475 44.60502 45.51479 44.86495 44.79997 
     250      251      252      253      254      255      256      257 
45.57977 45.70974 44.34508 45.31984 44.02017 44.99492 45.31984 46.09964 
     258      259      260      261      262      263      264      265 
44.60502 45.51479 44.79997 45.96967 45.25485 45.18987 44.73498 45.18987 
     266      267      268      269      270      271      273      274 
44.47505 45.90469 44.67000 44.86495 44.54003 46.16462 45.77472 44.86495 
     275      276      277      278      279      280      281      282 
45.44980 44.60502 43.43531 42.39558 42.59053 42.91544 42.20063 43.50030 
     283      284      285      286      287      288      289      290 
43.24036 43.24036 42.78548 42.13564 43.50030 41.87571 43.82521 43.30535 
     291      292      293      294      295      296      297      298 
43.95518 42.33059 42.07066 43.50030 42.98043 43.24036 43.82521 43.69525 
     299      300      301      302      303      304      305      306 
44.28010 42.46056 43.43531 42.72049 43.11040 42.72049 43.50030 42.07066 
     307      308      309      310      311      312      313      314 
44.28010 41.55079 44.21512 42.85046 42.98043 44.15013 43.17538 41.61577 
     315      316      317      318      319      320      321      322 
44.28010 42.13564 42.39558 43.69525 42.65551 44.02017 43.43531 43.04541 
     323      324      325      326      327      328      329      330 
43.43531 42.33059 42.91544 43.82521 44.41007 42.72049 43.82521 42.26561 
     331      332      333      334      335      336      337      338 
43.82521 42.85046 44.28010 42.13564 42.85046 42.46056 42.39558 44.34508 
     339      340      341      342      343      344 
44.02017 42.20063 43.30535 43.24036 42.72049 42.91544 

$assign
[1] 0 1

$qr
$qr
     (Intercept) bill_depth_mm
1   -18.49324201 -3.171807e+02
2     0.05407381 -3.646690e+01
3     0.05407381  2.109792e-02
5     0.05407381  5.674669e-02
6     0.05407381  9.239546e-02
7     0.05407381  1.561349e-02
8     0.05407381  6.497333e-02
9     0.05407381  2.384013e-02
10    0.05407381  8.142661e-02
11    0.05407381 -3.581997e-03
12    0.05407381  1.902429e-03
13    0.05407381  1.012907e-02
14    0.05407381  1.088487e-01
15    0.05407381  1.061065e-01
16    0.05407381  1.561349e-02
17    0.05407381  4.852005e-02
18    0.05407381  9.513767e-02
19    0.05407381  3.206677e-02
20    0.05407381  1.170754e-01
21    0.05407381  2.932456e-02
22    0.05407381  4.029341e-02
23    0.05407381  5.400448e-02
24    0.05407381  2.384013e-02
25    0.05407381 -8.397843e-04
26    0.05407381  4.577784e-02
27    0.05407381  3.755120e-02
28    0.05407381  1.835571e-02
29    0.05407381  3.755120e-02
30    0.05407381  4.577784e-02
31    0.05407381 -1.455085e-02
32    0.05407381  2.384013e-02
33    0.05407381  1.561349e-02
34    0.05407381  4.577784e-02
35    0.05407381 -6.324210e-03
36    0.05407381  1.061065e-01
37    0.05407381  7.594218e-02
38    0.05407381  3.480899e-02
39    0.05407381  5.674669e-02
40    0.05407381  5.126226e-02
41    0.05407381  2.109792e-02
42    0.05407381  3.206677e-02
43    0.05407381  3.480899e-02
44    0.05407381  6.771554e-02
45    0.05407381 -9.066424e-03
46    0.05407381  4.303562e-02
47    0.05407381  4.852005e-02
48    0.05407381  4.577784e-02
49    0.05407381  1.835571e-02
50    0.05407381  1.088487e-01
51    0.05407381  1.287128e-02
52    0.05407381  4.577784e-02
53    0.05407381  1.835571e-02
54    0.05407381  6.223112e-02
55    0.05407381  2.384013e-02
56    0.05407381  3.755120e-02
57    0.05407381  7.386855e-03
58    0.05407381  4.303562e-02
59    0.05407381 -1.729306e-02
60    0.05407381  5.126226e-02
61    0.05407381 -9.066424e-03
62    0.05407381  1.061065e-01
63    0.05407381 -6.324210e-03
64    0.05407381  2.658235e-02
65    0.05407381 -3.581997e-03
66    0.05407381  2.109792e-02
67    0.05407381 -2.826192e-02
68    0.05407381  5.126226e-02
69    0.05407381 -1.729306e-02
70    0.05407381  5.948890e-02
71    0.05407381  4.852005e-02
72    0.05407381  3.206677e-02
73    0.05407381 -8.397843e-04
74    0.05407381  4.577784e-02
75    0.05407381  7.386855e-03
76    0.05407381  3.480899e-02
77    0.05407381 -1.180864e-02
78    0.05407381  5.948890e-02
79    0.05407381 -3.100413e-02
80    0.05407381  5.126226e-02
81    0.05407381 -8.397843e-04
82    0.05407381  1.012907e-02
83    0.05407381  4.303562e-02
84    0.05407381  5.948890e-02
85    0.05407381  1.561349e-02
86    0.05407381  8.416882e-02
87    0.05407381  6.223112e-02
88    0.05407381  3.755120e-02
89    0.05407381  5.400448e-02
90    0.05407381  4.303562e-02
91    0.05407381  2.109792e-02
92    0.05407381  2.384013e-02
93    0.05407381 -3.581997e-03
94    0.05407381  2.384013e-02
95    0.05407381  1.902429e-03
96    0.05407381  4.577784e-02
97    0.05407381  3.755120e-02
98    0.05407381  3.480899e-02
99    0.05407381 -3.100413e-02
100   0.05407381  3.480899e-02
101   0.05407381  1.835571e-02
102   0.05407381  7.594218e-02
103   0.05407381 -3.374634e-02
104   0.05407381  7.594218e-02
105   0.05407381  3.755120e-02
106   0.05407381  4.577784e-02
107   0.05407381 -8.397843e-04
108   0.05407381  7.594218e-02
109   0.05407381 -6.324210e-03
110   0.05407381  4.852005e-02
111   0.05407381 -2.003528e-02
112   0.05407381  8.416882e-02
113   0.05407381  1.287128e-02
114   0.05407381  6.223112e-02
115   0.05407381  9.513767e-02
116   0.05407381  2.932456e-02
117   0.05407381 -6.324210e-03
118   0.05407381  8.965325e-02
119   0.05407381 -6.324210e-03
120   0.05407381  3.755120e-02
121   0.05407381 -8.397843e-04
122   0.05407381  7.045776e-02
123   0.05407381 -6.324210e-03
124   0.05407381  3.480899e-02
125   0.05407381 -3.648855e-02
126   0.05407381  4.852005e-02
127   0.05407381  1.012907e-02
128   0.05407381  2.932456e-02
129   0.05407381 -3.581997e-03
130   0.05407381  2.109792e-02
131   0.05407381  1.835571e-02
132   0.05407381  5.400448e-02
133   0.05407381  3.480899e-02
134   0.05407381  3.480899e-02
135   0.05407381  1.012907e-02
136   0.05407381  7.386855e-03
137   0.05407381  7.386855e-03
138   0.05407381  7.868439e-02
139   0.05407381 -2.003528e-02
140   0.05407381  1.835571e-02
141   0.05407381 -3.581997e-03
142   0.05407381 -8.397843e-04
143   0.05407381 -4.745741e-02
144   0.05407381 -6.324210e-03
145   0.05407381 -1.180864e-02
146   0.05407381  4.029341e-02
147   0.05407381  3.755120e-02
148   0.05407381  3.206677e-02
149   0.05407381  1.561349e-02
150   0.05407381  2.384013e-02
151   0.05407381 -3.581997e-03
152   0.05407381  3.480899e-02
153   0.05407381 -1.105283e-01
154   0.05407381 -2.551970e-02
155   0.05407381 -8.584839e-02
156   0.05407381 -5.568405e-02
157   0.05407381 -7.487954e-02
158   0.05407381 -1.023017e-01
159   0.05407381 -7.213732e-02
160   0.05407381 -5.294183e-02
161   0.05407381 -1.050439e-01
162   0.05407381 -5.019962e-02
163   0.05407381 -9.681724e-02
164   0.05407381 -3.100413e-02
165   0.05407381 -9.681724e-02
166   0.05407381 -7.213732e-02
167   0.05407381 -7.213732e-02
168   0.05407381 -4.197298e-02
169   0.05407381 -1.023017e-01
170   0.05407381 -5.568405e-02
171   0.05407381 -7.487954e-02
172   0.05407381 -5.842626e-02
173   0.05407381 -8.036396e-02
174   0.05407381 -7.487954e-02
175   0.05407381 -7.487954e-02
176   0.05407381 -3.923077e-02
177   0.05407381 -1.132705e-01
178   0.05407381 -5.842626e-02
179   0.05407381 -8.036396e-02
180   0.05407381 -6.116847e-02
181   0.05407381 -8.036396e-02
182   0.05407381 -5.294183e-02
183   0.05407381 -5.294183e-02
184   0.05407381 -8.310618e-02
185   0.05407381 -7.487954e-02
186   0.05407381 -6.324210e-03
187   0.05407381 -6.665290e-02
188   0.05407381 -2.551970e-02
189   0.05407381 -9.681724e-02
190   0.05407381  1.902429e-03
191   0.05407381 -9.955945e-02
192   0.05407381 -4.197298e-02
193   0.05407381 -9.681724e-02
194   0.05407381 -3.374634e-02
195   0.05407381 -9.681724e-02
196   0.05407381 -6.116847e-02
197   0.05407381 -3.648855e-02
198   0.05407381 -9.133282e-02
199   0.05407381 -9.133282e-02
200   0.05407381 -3.648855e-02
201   0.05407381 -1.077861e-01
202   0.05407381 -3.923077e-02
203   0.05407381 -8.310618e-02
204   0.05407381 -8.584839e-02
205   0.05407381 -7.762175e-02
206   0.05407381 -6.116847e-02
207   0.05407381 -7.762175e-02
208   0.05407381 -5.019962e-02
209   0.05407381 -9.133282e-02
210   0.05407381 -6.116847e-02
211   0.05407381 -7.487954e-02
212   0.05407381 -5.294183e-02
213   0.05407381 -9.407503e-02
214   0.05407381 -6.391068e-02
215   0.05407381 -9.133282e-02
216   0.05407381 -4.197298e-02
217   0.05407381 -8.310618e-02
218   0.05407381 -1.180864e-02
219   0.05407381 -7.762175e-02
220   0.05407381 -2.826192e-02
221   0.05407381 -8.310618e-02
222   0.05407381 -6.116847e-02
223   0.05407381 -6.116847e-02
224   0.05407381 -4.471519e-02
225   0.05407381 -4.471519e-02
226   0.05407381 -6.665290e-02
227   0.05407381 -6.116847e-02
228   0.05407381 -3.374634e-02
229   0.05407381 -8.310618e-02
230   0.05407381 -2.551970e-02
231   0.05407381 -9.407503e-02
232   0.05407381 -2.277749e-02
233   0.05407381 -7.487954e-02
234   0.05407381 -4.471519e-02
235   0.05407381 -7.213732e-02
236   0.05407381 -3.648855e-02
237   0.05407381 -9.407503e-02
238   0.05407381  1.902429e-03
239   0.05407381 -7.762175e-02
240   0.05407381 -8.310618e-02
241   0.05407381 -8.859060e-02
242   0.05407381 -6.324210e-03
243   0.05407381 -6.116847e-02
244   0.05407381 -3.581997e-03
245   0.05407381 -7.487954e-02
246   0.05407381 -3.100413e-02
247   0.05407381 -6.939511e-02
248   0.05407381 -4.197298e-02
249   0.05407381 -3.923077e-02
250   0.05407381 -7.213732e-02
251   0.05407381 -7.762175e-02
252   0.05407381 -2.003528e-02
253   0.05407381 -6.116847e-02
254   0.05407381 -6.324210e-03
255   0.05407381 -4.745741e-02
256   0.05407381 -6.116847e-02
257   0.05407381 -9.407503e-02
258   0.05407381 -3.100413e-02
259   0.05407381 -6.939511e-02
260   0.05407381 -3.923077e-02
261   0.05407381 -8.859060e-02
262   0.05407381 -5.842626e-02
263   0.05407381 -5.568405e-02
264   0.05407381 -3.648855e-02
265   0.05407381 -5.568405e-02
266   0.05407381 -2.551970e-02
267   0.05407381 -8.584839e-02
268   0.05407381 -3.374634e-02
269   0.05407381 -4.197298e-02
270   0.05407381 -2.826192e-02
271   0.05407381 -9.681724e-02
273   0.05407381 -8.036396e-02
274   0.05407381 -4.197298e-02
275   0.05407381 -6.665290e-02
276   0.05407381 -3.100413e-02
277   0.05407381  1.835571e-02
278   0.05407381  6.223112e-02
279   0.05407381  5.400448e-02
280   0.05407381  4.029341e-02
281   0.05407381  7.045776e-02
282   0.05407381  1.561349e-02
283   0.05407381  2.658235e-02
284   0.05407381  2.658235e-02
285   0.05407381  4.577784e-02
286   0.05407381  7.319997e-02
287   0.05407381  1.561349e-02
288   0.05407381  8.416882e-02
289   0.05407381  1.902429e-03
290   0.05407381  2.384013e-02
291   0.05407381 -3.581997e-03
292   0.05407381  6.497333e-02
293   0.05407381  7.594218e-02
294   0.05407381  1.561349e-02
295   0.05407381  3.755120e-02
296   0.05407381  2.658235e-02
297   0.05407381  1.902429e-03
298   0.05407381  7.386855e-03
299   0.05407381 -1.729306e-02
300   0.05407381  5.948890e-02
301   0.05407381  1.835571e-02
302   0.05407381  4.852005e-02
303   0.05407381  3.206677e-02
304   0.05407381  4.852005e-02
305   0.05407381  1.561349e-02
306   0.05407381  7.594218e-02
307   0.05407381 -1.729306e-02
308   0.05407381  9.787989e-02
309   0.05407381 -1.455085e-02
310   0.05407381  4.303562e-02
311   0.05407381  3.755120e-02
312   0.05407381 -1.180864e-02
313   0.05407381  2.932456e-02
314   0.05407381  9.513767e-02
315   0.05407381 -1.729306e-02
316   0.05407381  7.319997e-02
317   0.05407381  6.223112e-02
318   0.05407381  7.386855e-03
319   0.05407381  5.126226e-02
320   0.05407381 -6.324210e-03
321   0.05407381  1.835571e-02
322   0.05407381  3.480899e-02
323   0.05407381  1.835571e-02
324   0.05407381  6.497333e-02
325   0.05407381  4.029341e-02
326   0.05407381  1.902429e-03
327   0.05407381 -2.277749e-02
328   0.05407381  4.852005e-02
329   0.05407381  1.902429e-03
330   0.05407381  6.771554e-02
331   0.05407381  1.902429e-03
332   0.05407381  4.303562e-02
333   0.05407381 -1.729306e-02
334   0.05407381  7.319997e-02
335   0.05407381  4.303562e-02
336   0.05407381  5.948890e-02
337   0.05407381  6.223112e-02
338   0.05407381 -2.003528e-02
339   0.05407381 -6.324210e-03
340   0.05407381  7.045776e-02
341   0.05407381  2.384013e-02
342   0.05407381  2.658235e-02
343   0.05407381  4.852005e-02
344   0.05407381  4.029341e-02
attr(,"assign")
[1] 0 1

$qraux
[1] 1.054074 1.004645

$pivot
[1] 1 2

$tol
[1] 1e-07

$rank
[1] 2

attr(,"class")
[1] "qr"

$df.residual
[1] 340

$na.action
  4 272 
  4 272 
attr(,"class")
[1] "omit"

$xlevels
named list()

$call
lm(formula = bill_length_mm ~ bill_depth_mm, data = palmerpenguins::penguins)

$terms
bill_length_mm ~ bill_depth_mm
attr(,"variables")
list(bill_length_mm, bill_depth_mm)
attr(,"factors")
               bill_depth_mm
bill_length_mm             0
bill_depth_mm              1
attr(,"term.labels")
[1] "bill_depth_mm"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(bill_length_mm, bill_depth_mm)
attr(,"dataClasses")
bill_length_mm  bill_depth_mm 
     "numeric"      "numeric" 

$model
    bill_length_mm bill_depth_mm
1             39.1          18.7
2             39.5          17.4
3             40.3          18.0
5             36.7          19.3
6             39.3          20.6
7             38.9          17.8
8             39.2          19.6
9             34.1          18.1
10            42.0          20.2
11            37.8          17.1
12            37.8          17.3
13            41.1          17.6
14            38.6          21.2
15            34.6          21.1
16            36.6          17.8
17            38.7          19.0
18            42.5          20.7
19            34.4          18.4
20            46.0          21.5
21            37.8          18.3
22            37.7          18.7
23            35.9          19.2
24            38.2          18.1
25            38.8          17.2
26            35.3          18.9
27            40.6          18.6
28            40.5          17.9
29            37.9          18.6
30            40.5          18.9
31            39.5          16.7
32            37.2          18.1
33            39.5          17.8
34            40.9          18.9
35            36.4          17.0
36            39.2          21.1
37            38.8          20.0
38            42.2          18.5
39            37.6          19.3
40            39.8          19.1
41            36.5          18.0
42            40.8          18.4
43            36.0          18.5
44            44.1          19.7
45            37.0          16.9
46            39.6          18.8
47            41.1          19.0
48            37.5          18.9
49            36.0          17.9
50            42.3          21.2
51            39.6          17.7
52            40.1          18.9
53            35.0          17.9
54            42.0          19.5
55            34.5          18.1
56            41.4          18.6
57            39.0          17.5
58            40.6          18.8
59            36.5          16.6
60            37.6          19.1
61            35.7          16.9
62            41.3          21.1
63            37.6          17.0
64            41.1          18.2
65            36.4          17.1
66            41.6          18.0
67            35.5          16.2
68            41.1          19.1
69            35.9          16.6
70            41.8          19.4
71            33.5          19.0
72            39.7          18.4
73            39.6          17.2
74            45.8          18.9
75            35.5          17.5
76            42.8          18.5
77            40.9          16.8
78            37.2          19.4
79            36.2          16.1
80            42.1          19.1
81            34.6          17.2
82            42.9          17.6
83            36.7          18.8
84            35.1          19.4
85            37.3          17.8
86            41.3          20.3
87            36.3          19.5
88            36.9          18.6
89            38.3          19.2
90            38.9          18.8
91            35.7          18.0
92            41.1          18.1
93            34.0          17.1
94            39.6          18.1
95            36.2          17.3
96            40.8          18.9
97            38.1          18.6
98            40.3          18.5
99            33.1          16.1
100           43.2          18.5
101           35.0          17.9
102           41.0          20.0
103           37.7          16.0
104           37.8          20.0
105           37.9          18.6
106           39.7          18.9
107           38.6          17.2
108           38.2          20.0
109           38.1          17.0
110           43.2          19.0
111           38.1          16.5
112           45.6          20.3
113           39.7          17.7
114           42.2          19.5
115           39.6          20.7
116           42.7          18.3
117           38.6          17.0
118           37.3          20.5
119           35.7          17.0
120           41.1          18.6
121           36.2          17.2
122           37.7          19.8
123           40.2          17.0
124           41.4          18.5
125           35.2          15.9
126           40.6          19.0
127           38.8          17.6
128           41.5          18.3
129           39.0          17.1
130           44.1          18.0
131           38.5          17.9
132           43.1          19.2
133           36.8          18.5
134           37.5          18.5
135           38.1          17.6
136           41.1          17.5
137           35.6          17.5
138           40.2          20.1
139           37.0          16.5
140           39.7          17.9
141           40.2          17.1
142           40.6          17.2
143           32.1          15.5
144           40.7          17.0
145           37.3          16.8
146           39.0          18.7
147           39.2          18.6
148           36.6          18.4
149           36.0          17.8
150           37.8          18.1
151           36.0          17.1
152           41.5          18.5
153           46.1          13.2
154           50.0          16.3
155           48.7          14.1
156           50.0          15.2
157           47.6          14.5
158           46.5          13.5
159           45.4          14.6
160           46.7          15.3
161           43.3          13.4
162           46.8          15.4
163           40.9          13.7
164           49.0          16.1
165           45.5          13.7
166           48.4          14.6
167           45.8          14.6
168           49.3          15.7
169           42.0          13.5
170           49.2          15.2
171           46.2          14.5
172           48.7          15.1
173           50.2          14.3
174           45.1          14.5
175           46.5          14.5
176           46.3          15.8
177           42.9          13.1
178           46.1          15.1
179           44.5          14.3
180           47.8          15.0
181           48.2          14.3
182           50.0          15.3
183           47.3          15.3
184           42.8          14.2
185           45.1          14.5
186           59.6          17.0
187           49.1          14.8
188           48.4          16.3
189           42.6          13.7
190           44.4          17.3
191           44.0          13.6
192           48.7          15.7
193           42.7          13.7
194           49.6          16.0
195           45.3          13.7
196           49.6          15.0
197           50.5          15.9
198           43.6          13.9
199           45.5          13.9
200           50.5          15.9
201           44.9          13.3
202           45.2          15.8
203           46.6          14.2
204           48.5          14.1
205           45.1          14.4
206           50.1          15.0
207           46.5          14.4
208           45.0          15.4
209           43.8          13.9
210           45.5          15.0
211           43.2          14.5
212           50.4          15.3
213           45.3          13.8
214           46.2          14.9
215           45.7          13.9
216           54.3          15.7
217           45.8          14.2
218           49.8          16.8
219           46.2          14.4
220           49.5          16.2
221           43.5          14.2
222           50.7          15.0
223           47.7          15.0
224           46.4          15.6
225           48.2          15.6
226           46.5          14.8
227           46.4          15.0
228           48.6          16.0
229           47.5          14.2
230           51.1          16.3
231           45.2          13.8
232           45.2          16.4
233           49.1          14.5
234           52.5          15.6
235           47.4          14.6
236           50.0          15.9
237           44.9          13.8
238           50.8          17.3
239           43.4          14.4
240           51.3          14.2
241           47.5          14.0
242           52.1          17.0
243           47.5          15.0
244           52.2          17.1
245           45.5          14.5
246           49.5          16.1
247           44.5          14.7
248           50.8          15.7
249           49.4          15.8
250           46.9          14.6
251           48.4          14.4
252           51.1          16.5
253           48.5          15.0
254           55.9          17.0
255           47.2          15.5
256           49.1          15.0
257           47.3          13.8
258           46.8          16.1
259           41.7          14.7
260           53.4          15.8
261           43.3          14.0
262           48.1          15.1
263           50.5          15.2
264           49.8          15.9
265           43.5          15.2
266           51.5          16.3
267           46.2          14.1
268           55.1          16.0
269           44.5          15.7
270           48.8          16.2
271           47.2          13.7
273           46.8          14.3
274           50.4          15.7
275           45.2          14.8
276           49.9          16.1
277           46.5          17.9
278           50.0          19.5
279           51.3          19.2
280           45.4          18.7
281           52.7          19.8
282           45.2          17.8
283           46.1          18.2
284           51.3          18.2
285           46.0          18.9
286           51.3          19.9
287           46.6          17.8
288           51.7          20.3
289           47.0          17.3
290           52.0          18.1
291           45.9          17.1
292           50.5          19.6
293           50.3          20.0
294           58.0          17.8
295           46.4          18.6
296           49.2          18.2
297           42.4          17.3
298           48.5          17.5
299           43.2          16.6
300           50.6          19.4
301           46.7          17.9
302           52.0          19.0
303           50.5          18.4
304           49.5          19.0
305           46.4          17.8
306           52.8          20.0
307           40.9          16.6
308           54.2          20.8
309           42.5          16.7
310           51.0          18.8
311           49.7          18.6
312           47.5          16.8
313           47.6          18.3
314           52.0          20.7
315           46.9          16.6
316           53.5          19.9
317           49.0          19.5
318           46.2          17.5
319           50.9          19.1
320           45.5          17.0
321           50.9          17.9
322           50.8          18.5
323           50.1          17.9
324           49.0          19.6
325           51.5          18.7
326           49.8          17.3
327           48.1          16.4
328           51.4          19.0
329           45.7          17.3
330           50.7          19.7
331           42.5          17.3
332           52.2          18.8
333           45.2          16.6
334           49.3          19.9
335           50.2          18.8
336           45.6          19.4
337           51.9          19.5
338           46.8          16.5
339           45.7          17.0
340           55.8          19.8
341           43.5          18.1
342           49.6          18.2
343           50.8          19.0
344           50.2          18.7

attr(,"class")
[1] "lm"

Writing print methods

All of our communication principles apply to print methods:

  • Important information first
  • Unnecessary information hidden
  • Conciseness
  • Clarity

Often this will need multiple rounds of feedback (like all writing).

Including print methods in packages

To include your custom print method in the package, you have to register an S3 object. This is out of scope for the unit, but if you are interested, you can read more in the R packages manual.

Week 9 Lesson

Summary

  • Package documentation is important to let others know about the goal of the package, what your function does, and how to use your package.
  • Sharing your package by making it easy to install, implementing unit tests, commiting to good documentation, and making the documentation accessible helps to build trust to use your package.
  • You can make package development and distribution easy with usethis, devtools, and roxygen2.