Description Usage Arguments Details Value Acknowledgment Author(s) Examples
These functions read and wrangle excel workbooks produced by the FastField
app and output a list of dataframes (xlff_to_list()
), .csv files
(xlff_to_csv()
) or .xlsx files (xlff_to_xl()
). Each dataframe or file
combines all spreadsheets from a single excel workbook in the input
directory. If the input directory has multiple workbooks, the output will be
multiple dataframes, multiple .csv files, or multiple .excel files.
1 2 3 4 5 | xlff_to_csv(dir_in, dir_out = "./", first_census = FALSE)
xlff_to_xl(dir_in, dir_out = "./", first_census = FALSE)
xlff_to_list(dir_in, first_census = FALSE, root_columns = NULL)
|
dir_in |
String giving the directory containing the excel workbooks to read from. |
dir_out |
String giving the directory where to write .csv files to. |
first_census |
Use |
root_columns |
String. Lowercase name of column(s) in the root sheet ( e.g. c("date", "team")). This is useful when you data has non-standard columns. |
This is a rigid function with a very specific goal: To process data from FastField forms. Specifically, this is what this function does:
Reads each spreadsheet from each workbook and map it to a dataframe.
Lowercases and links the names of each dataframe.
Adds any missing key-sheets:
For first census: (1) "root", (2) "multi_stems", (3) "secondary_stems", and (4) "single_stems".
For recensus: (1) "root", (2) "original_stems", (3) "new_secondary_stems", and (4) "recruits"
Dates the data by submission_id
(date
comes from the spreadsheet
root
).
Lowercases and links the names of each dataframe-variable.
Drops fake stems.
Output a common data structure of your choice.
xlff_to_csv()
and xlff_to_xl()
write a .csv or excel (.xlsx) file
per workbook – combining all spreadsheets. xlff_to_list
outputs a list
where each dataframes combines all spreadsheeets of a workbook.
Sabrina Russo helped to make these functions useful with first censuses.
David Orwig helped to fix a debug.
Mauro Lepore and Jessica Shue.
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 27 28 29 30 31 32 33 34 35 36 | library(fs)
library(readr)
library(readxl)
# NOT A FIRST CENSUS
# Path to the folder I want to read excel files from
dir_in <- dirname(misc_example("two_files/new_stem_1.xlsx"))
dir_in
# Files I want to read
dir(dir_in, pattern = "xlsx")
# Path to the folder I want to write .csv files to
dir_out <- tempdir()
# Output a csv file
xlff_to_csv(dir_in, dir_out)
# Confirm
path_file(dir_ls(dir_out, regexp = "new_stem.*csv$"))
# Also possible to output excel and a list of dataframe. See next section.
# FIRST CENSUS
dir_in <- dirname(misc_example("first_census/census.xlsx"))
# As a reminder you will get a warning of missing sheets
# Output list of dataframes (one per input workbook -- here only one)
lst <- xlff_to_list(dir_in, first_census = TRUE)
str(lst, give.attr = FALSE)
# Output excel
xlff_to_xl(dir_in, dir_out, first_census = TRUE)
# Read back
filename <- path(dir_out, "census.xlsx")
out <- read_excel(filename)
str(out, give.attr = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.