Remapping and Ellipsis

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Remapping

There are two conventions of arguments among the underlying functions used by rio. Let's call them Base Convention and "Tidy" Convention.

| Convention | file location | selection of sheet | header | examples | |------------|---------------|--------------------|-------------|--------------------------------------------------------------| | Base | file | which | header | clipr::read_clip_tbl | | "Tidy" | path | sheet | col_names | readxl::read_xlsx, readxl::read_xls, readODS::read_ods |

rio can map Base Convention into "Tidy" Convention (but not vice versa).

library(rio)
export(list("mtcars" = mtcars, "iris" = iris), "example.xlsx")
import("example.xlsx", which = "mtcars")

But you can still use the "Tidy" Convention, if the underlying function supports it.

import("example.xlsx", sheet = "mtcars")

Ellipsis or "dot dot dot"

Additional parameters are usually passed to the underlying function as ellipsis (...).

## n_max is an argument of readxl::read_xlsx
import("example.xlsx", sheet = "iris", n_max = 10)

Parameters that the underlying function do not recognize are silently ignored by default.

import("example.xlsx", sheet = "iris", n_max = 10, pizza = "pineapple")

If you don't like this behavior, please change the option rio.ignoreunusedargs to FALSE, i.e. options(rio.ignoreunusedargs = FALSE).

options(rio.ignoreunusedargs = FALSE)
import("example.xlsx", sheet = "iris", n_max = 10, pizza = "pineapple")
R.utils::withOptions({
    import("example.xlsx", sheet = "iris", n_max = 10, pizza = "pineapple")
}, rio.ignoreunusedargs = FALSE)
unlink("example.xlsx")


Try the rio package in your browser

Any scripts or data that you put into this service are public.

rio documentation built on Sept. 26, 2024, 1:07 a.m.