locate_groups: Locate multiple header groups

Description Usage Arguments Examples

View source: R/locatate_header_groups.R

Description

This function adds direction annations to tidyxl data frame, specifying annotions for several headers at once. The resulting data frame will contain the following columns: .value, .direction, and .header_label. These columns indicate the value, direction and name of the header columns that will be produced in the tidy data frame produced by migrate.

Usage

1
2
3
4
5
locate_groups(sheet = NULL, direction = "N",
  .groupings = groupings(fmt_alignment_indent),
  .hook_if = hook_if(any(FALSE)), .hook_if_rev = hook_if(any(FALSE)),
  default_col_header_direction = "N",
  default_row_header_direction = "W", header_fill = "local_format_id")

Arguments

sheet

data frame created by xlsx_cells

direction

a string indicating which type of headers are to be labelled. Options include compass direction or up/down/left/right.

.groupings

expressions representing how header cells are differentiated. Most naturally works with fmt_* functions. These expressions must be provided within groupings.

.hook_if

expression determining whether directions are hooked. That is, whether a header cell to the left of data cells should be annotated as "W" or "WNW". This argument contains an expression within the function hook. This expression must evaluate to a single value for each header group. For example, see below that any(fmt_alignment_indent == 0) is used rather that fmt_alignment_indent == 0.

.hook_if_rev

expression determining whether directions are hooked. That is, whether a header cell to the left of data cells should be annotated as "W" or "WNW". This argument contains an expression within the function hook. This expression must evaluate to a single value for each header group. For example, see below that any(fmt_alignment_indent == 0) is used rather that fmt_alignment_indent == 0.

default_col_header_direction

Indicates which direction is given to col headers by default. Only need if "NNW" is required, rather than "N".

default_row_header_direction

Indicates which direction is given to row headers by default. Only need if "WNW" is required, rather than "W".

header_fill

deals with merged cells. Fills in neighbouring cells if they have the same "local_format_id", "style" or are within "borders".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Not run: 

library(tidyverse)

# Read in tidyxl data frame
xl_df <-
  locatr_example("worked-examples.xlsx") %>%
  xlsx_cells_fmt(sheets = "pivot-hierarchy") %>%
  append_fmt(fmt_alignment_indent)

# Add location annotations
xl_df <-
  xl_df %>%
  locate_data(data_type == "numeric") %>%
  locate_groups(
    direction = "W",
    .groupings = groupings(fmt_alignment_indent),
    .hook_if = hook_if(any(fmt_alignment_indent == 0))
  ) %>%
  locate(direction = "N", name = student)

# Use `migrate` to reshape the data frame such that each data cells has its own row and each
 header variable has its own column.
xl_df %>% migrate()

## End(Not run)

ianmoran11/locatr documentation built on June 14, 2020, 3:32 a.m.