R/replace_blanks.R
replace_blanks.Rd
replace_blanks()
is particularly useful for exporting data
from a database (such as access) and converting it to a data package with
metadata.
replace_blanks()
will import all .csv files in the specified working
directory. The files are then written back out to the same directory,
overwriting the old .csv files. Any blank cells (or cells with "NA" in the
original .csv files) will be replaced with the specified string or integer.
If no missing value is specified, the function defaults to replacing all
blanks with "NA".
Please keep in mind the "missing" is a general term for all data not present in the data file or data package. Although you may have a very good reason for not providing data and that data may not, from the data package creator's perspective, be "missing" (maybe you never intended to collect it) from a data package user's perspective any data that is not in the data package is effectively "missing" from the data package. Therefore, it is critical to document in metadata any data that are absent with an appropriate "missingValueCode" and "missingValueDefinition". These terms are defined by the metadata schema and are broadly used to apply to any data not present.
This function will replace all empty cells and all cells with NA with a "missingValueCode" of your choice (although it defaults to NA).
replace_blanks(directory = here::here(), missing_val_code = NA)
list of data frames (invisibly)
One exception is if a .csv contains NO data (i.e. just column names and no data in any of the cells). In this case, the blanks will not be replaced with NA (as the function cannot determine how many NAs to include).
if (FALSE) { # \dontrun{
#replaces all blank cells in .csvs in the current directory with NA:
replace_blanks()
#replace all blank cells in .csvs in the directory ./test_data with "NODATA"
dir <- here::here("test_data")
replace_blanks(directory = dir, missing_val_code = "NODATA")
#replace all blank cells in .csvs in the current directory with -99999
replace_blanks(missing_val_code = -99999)
} # }