Skip to contents

dpjr comes bundled with various data files in its `inst/extdata` directory. This function make them easy to access.

Usage

dpjr_data(path = NULL)

Source

This function is adapted from `readxl::readxl_example()` and `palmerpenguins::path_to_file`.

Arguments

path

Name of file in quotes with extension; for example `"mpg.csv"` will work. If `NULL`, the example files will be listed.

Examples

# return a list of all the files in the package
dpjr_data()
#>  [1] "JCUSH.txt"                               
#>  [2] "Video_SPSS.sav"                          
#>  [3] "authors2_fwf.txt"                        
#>  [4] "authors_count_fwf.txt"                   
#>  [5] "authors_fwf.txt"                         
#>  [6] "badpenguins.rds"                         
#>  [7] "bcferries_2021.pdf"                      
#>  [8] "canpop.csv"                              
#>  [9] "census2021firstresultsenglandwales1.xlsx"
#> [10] "cr25"                                    
#> [11] "date.xlsx"                               
#> [12] "gapminder.csv"                           
#> [13] "intl_tuition_fees_bc.xlsx"               
#> [14] "lahman_2020.zip"                         
#> [15] "lfs_canada_employment.rds"               
#> [16] "mpg.csv"                                 
#> [17] "mtcars.csv"                              
#> [18] "noc_table.rds"                           
#> [19] "nycflights13_sql.zip"                    
#> [20] "penguin_summary.pdf"                     
#> [21] "penguins.csv"                            
#> [22] "penguins.dta"                            
#> [23] "penguins.sas"                            
#> [24] "penguins.sav"                            
#> [25] "penguins_fwf.txt"                        
#> [26] "penguins_fwf_code.txt"                   
#> [27] "penguins_spss_output.xlsx"               
#> [28] "seph_naics721_bc_sal.rds"                
#> [29] "us_bls_employment_2010-2020.csv"         
#
# return the full path of the named file
dpjr_data("mpg.csv")
#> [1] "/home/runner/work/_temp/Library/dpjr/extdata/mpg.csv"
#
# return the head (first 6 rows) of the named file
head(read.csv(dpjr_data("mpg.csv")))
#>   manufacturer model displ year cyl      trans drv cty hwy fl   class
#> 1         audi    a4   1.8 1999   4   auto(l5)   f  18  29  p compact
#> 2         audi    a4   1.8 1999   4 manual(m5)   f  21  29  p compact
#> 3         audi    a4   2.0 2008   4 manual(m6)   f  20  31  p compact
#> 4         audi    a4   2.0 2008   4   auto(av)   f  21  30  p compact
#> 5         audi    a4   2.8 1999   6   auto(l5)   f  16  26  p compact
#> 6         audi    a4   2.8 1999   6 manual(m5)   f  18  26  p compact