assign_colnames: Make a specific row the column names for the specified...

Description Usage Arguments Value See Also Examples

View source: R/assign_colnames.r

Description

Many tables in Word documents are in twisted formats where there may be labels or other oddities mixed in that make it difficult to work with the underlying data. This function makes it easy to identify a particular row in a scraped data.frame as the one containing column names and have it become the column names, removing it and (optionally) all of the rows before it (since that's usually what needs to be done).

Usage

1
assign_colnames(dat, row, remove = TRUE, remove_previous = remove)

Arguments

dat

can be any data.frame but is intended for use with ones retuned by this package

row

numeric value indicating the row number that is to become the column names

remove

remove row specified by row after making it the column names? (Default: TRUE)

remove_previous

remove any rows preceding row? (Default: TRUE but will be assigned whatever is given for remove).

Value

data.frame

See Also

docx_extract_all, docx_extract_tbl

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# a "real" Word doc
real_world <- read_docx(system.file("examples/realworld.docx", package="docxtractr"))
docx_tbl_count(real_world)

# get all the tables
tbls <- docx_extract_all_tbls(real_world)

# make table 1 better
assign_colnames(tbls[[1]], 2)

# make table 5 better
assign_colnames(tbls[[5]], 2)

hrbrmstr/docxtractr documentation built on July 11, 2020, 10:06 p.m.