read_and_join: Read in an external file and join it with an existing data...

View source: R/Apply_Lookups.R

read_and_joinR Documentation

Read in an external file and join it with an existing data frame

Description

Read in an external file and join it with an existing data frame

Usage

read_and_join(
  data,
  lookup_file,
  path = "https://raw.githubusercontent.com/CSISdefense/R-scripts-and-data/master/",
  directory = "Lookups/",
  by = NULL,
  replace_na_var = NULL,
  overlap_var_replaced = TRUE,
  add_var = NULL,
  new_var_checked = TRUE,
  skip_check_var = NULL,
  missing_file = NULL,
  lookup_char_as_factor = FALSE
)

Arguments

data

The data frame to be joined

lookup_file

The name of the lookup file

by

The columns used to join, if not provided, matching columns will be used

replace_na_var

Before the join, these columns will have NAs values replaced

overlap_var_replaced

Should the function replace for common columns not used to join?

add_var

What new columns should be checked for NA values?

new_var_checked

Should only checked new columns be kept?

skip_check_var

List of vars that should not be checked for NA values

missing_file

Filename to output any unmatched variables for easy of processing

path="https://github.com/CSISdefense/R-scripts-and-data/tree/master/"

The location of the lookup file

directory="Lookups\"

The directory within the path that holds the lookup

Details

This function is an elaborate join with various quality check measures thrown in. At its simplest, it just joins the existing data frame with the passed file. But along the way it will make some fixes to common CSV errors and also take advantage of some known facts about how CSIS data is organized.

Value

The data frame plus new columns from the lookup file. If new_var_checked is true and only new columns listed in add_var will be kept. Note to self, should add input protection that throws an error if new_var_checked is set to true when add_var is false.

Examples

na_check(data,
  input_var=by,
  output_var=add_var,
  lookup_file=lookup_file)


CSISdefense/csis360 documentation built on April 14, 2024, 12:16 p.m.