locate_groups_if: Locate multiple header groups

Description Usage Arguments Examples

View source: R/locatate_header_groups.R

Description

This function conditionally 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_if(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

...

filter expression that identifies headers.

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.

.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
## Not run: 

library(tidyverse)

# Read in tidyxl data frame
xl_df <-
  locatr_example("anzsic.xlsx") %>%
  xlsx_cells_fmt(sheets = "Classes") %>%
  filter_fmt(row > 6) # Remove irrelevant rows

# Identify data cells.
xl_df <-
  xl_df %>%
  locate_data(col == 6 & is_blank == FALSE)

# Add annotations for header cells that are numbers first, and then for header cells
 that are words.
xl_df <-
  xl_df %>%
  locate_groups_if(str_detect(character, "[0-9]"), direction = "W",
  .hook_if = locatr::hook_if(TRUE)) %>%
  locate_groups_if(str_detect(character, "[a-z]"), direction = "W",
   .hook_if = locatr::hook_if(TRUE))
   
## End(Not run)

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