There are two functions to "rectify" a set of ODS cells extracted by
read_ods_cells()
back into a traditional two-dimensional spreadsheet
rectangle.
Usage
simple_rectify(
ods_cells,
skip = 0,
col_headers = TRUE,
values_from = "base_value"
)
smart_rectify(ods_cells)
Arguments
- ods_cells
A set of cells from
read_ods_cells()
.- skip
The number of rows to skip before extracting the sheet.
- col_headers
Whether to use the first row (after any skipping) as the column header (
TRUE
is the default), alternatively a character vector of column names can be provided.- values_from
The column from
ods_cells
to output values from.
Details
simple_rectify()
will perform a basic reshaping of the dataset, by default
it will use the base_value
extracted by read_ods_cells()
but this can
be changed to a different column by setting the values_from
argument. The
rectifier will also by default try to use the first row for column headers,
alternatively you can provide your own column names or set
col_headers = FALSE
to get generic column names of x1
, x2
, etc.
smart_rectify()
performs a more complex reshaping of the dataset, by
guessing the location of column headers and using the value_type
information generated by read_ods_cells()
to determine whether columns can
be coerced to a non-string data type (either numeric, logical, date or time).
Examples
example <- system.file("extdata", "basic_example.ods", package = "tidyods")
example_cells <- read_ods_cells(example, 1)
simple_rectify(example_cells)
#> # A tibble: 6 × 4
#> species female bill_length_mm body_mass_g
#> <chr> <chr> <chr> <chr>
#> 1 Adelie false 40.3904109589041 4043.49315068493
#> 2 Adelie true 37.2575342465753 3368.83561643836
#> 3 Chinstrap false 51.0941176470588 3938.97058823529
#> 4 Chinstrap true 46.5735294117647 3527.20588235294
#> 5 Gentoo false 49.4737704918033 5484.83606557377
#> 6 Gentoo true 45.5637931034483 4679.74137931035
smart_rectify(example_cells)
#> # A tibble: 6 × 4
#> species female bill_length_mm body_mass_g
#> <chr> <lgl> <dbl> <dbl>
#> 1 Adelie FALSE 40.4 4043.
#> 2 Adelie TRUE 37.3 3369.
#> 3 Chinstrap FALSE 51.1 3939.
#> 4 Chinstrap TRUE 46.6 3527.
#> 5 Gentoo FALSE 49.5 5485.
#> 6 Gentoo TRUE 45.6 4680.