loading...

Define the functions that read() or write() must call to import or export data for the different types (formats).

read_write_option(new_type)

Arguments

new_type

A data.frame with four columns: type, read_fun, read_header and write_fun containing each a single character string or NA. type is the usual extension for this type of file, e.g., png for PNG images, read_fun, read_header and write_fun are character strings with "pkg::fun" format ("pkg" is the package containing the function and "fun" is the function name), or just "fun" if the function is visible on the search path.

Value

The data.frame with all known formats is returned invisibly. The same data.frame is also saved in the read_write option, and can be retrieved directly with getOption("read_write").

See also

Author

Philippe Grosjean phgrosjean@sciviews.org

Examples

# The default options
(read_write_option())
#> # A tibble: 44 × 5
#>    type     read_fun         read_header         write_fun              comment 
#>    <chr>    <chr>            <chr>               <chr>                  <chr>   
#>  1 csv      fread2           data.io::hread_text data.table::fwrite     comma s…
#>  2 csv_alt  readr::read_csv  data.io::hread_text readr::write_csv       comma s…
#>  3 csv2     fread2           data.io::hread_text data.table::fwrite     semicol…
#>  4 csv2_alt readr::read_csv2 data.io::hread_text NA                     semicol…
#>  5 xlcsv    readr::read_csv  data.io::hread_text readr::write_excel_csv write a…
#>  6 tsv      fread2           data.io::hread_text data.table::fwrite     tab sep…
#>  7 tsv_alt  readr::read_tsv  data.io::hread_text readr::write_tsv       tab sep…
#>  8 fwf      readr::read_fwf  data.io::hread_text NA                     fixed w…
#>  9 log      readr::read_log  NA                  NA                     standar…
#> 10 rds      readr::read_rds  NA                  readr::write_rds       R data …
#> # ℹ 34 more rows
# To add a new type:
tail(read_write_option(data.frame(type = "png", read_fun = "png::readPNG",
  read_header = NA, write_fun = "png::writePNG", comment = "PNG image")))
#> # A tibble: 6 × 5
#>   type     read_fun        read_header write_fun        comment                 
#>   <chr>    <chr>           <chr>       <chr>            <chr>                   
#> 1 sas7bdat haven::read_sas NA          haven::write_sas SAS format (sas7bdat)   
#> 2 sav      haven::read_sav NA          haven::write_sav SPSS .sav format        
#> 3 zsav     haven::read_sav NA          haven::write_sav SPSS .zsav format       
#> 4 por      haven::read_por NA          NA               SPSS .por format        
#> 5 xpt      haven::read_xpt NA          haven::write_xpt SPSS transport format (…
#> 6 png      png::readPNG    NA          png::writePNG    PNG image