locate: Add direction annations to tidyxl data frame

Description Usage Arguments Examples

View source: R/locate.R

Description

This function adds direction annations to tidyxl data frame. 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.

The header cells for which annotations are the outermost. For example, if "left" of "W" is used for the direction argument, cells furthest to the left in your spreadsheet will have location information added.

Usage

1
2
locate(cells, direction, name, values = NULL, types = data_type,
  formatters = list(), drop_na = TRUE)

Arguments

cells

a tidyxl data frame

direction

direction of new headers

name

of variable associated with header

values

values

types

types

formatters

formatters

drop_na

drop_na

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)

xl_df <-
locatr_example("worked-examples.xlsx") %>%
 xlsx_cells_fmt(sheets = "pivot-annotations")

# Identfy which cells are data cells using `locate_data`

 xl_df <- xl_df %>% locate_data(data_type == "numeric")

 # Identify header cells, indicating their direction with respect to the data and a name for
 their column in the final tidy data frame.
 xl_df <-
  xl_df %>%
   locate(direction = "WNW", name = subject_type) %>%
   locate(direction = "W", name = subject) %>%
   locate(direction = "NNW", name = gender) %>%
   locate(direction = "N", name = name)

 # 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.