cs_prep_year: Prepare Raw Data

View source: R/create.R

cs_prep_yearR Documentation

Prepare Raw Data

Description

Data downloaded from the St. Louis Metropolitan Police Department are downloaded with incorrect file paths - e.g. January2008.CSV.html. This function iterates over all files in a given path and replaces their file extensions. Thus January2008.CSV.html will be replaced by january2008.csv. There should be no more than 12 files in a given path, and all should correspond to the same year.

Usage

cs_prep_year(path, verbose = FALSE)

Arguments

path

File path where raw STLMPD data are

verbose

If TRUE, returns a tibble with results; otherwise if FALSE, no output is returned.

Value

A tibble containing old file names and new file names for reference is verbose = TRUE. Otherwise, no output is returned. This function will change all problematic filenames in the specified path.

Examples

# create temporary directory
tmpdir <- tempdir()
fs::dir_create(paste0(tmpdir,"/data/"))

# load sample files into temporary directory
cs_example(path = paste0(tmpdir,"/data/"))

# list files
list.files(paste0(tmpdir,"/data/"))

# prep sample files
cs_prep_year(path = paste0(tmpdir,"/data/"))

# list files again
list.files(paste0(tmpdir,"/data/"))

# delete data
fs::dir_delete(paste0(tmpdir,"/data/"))

# create temporary directory
fs::dir_create(paste0(tmpdir,"/data/"))

# load sample files into temporary directory
cs_example(path = paste0(tmpdir,"/data/"))

# prep sample files
cs_prep_year(path = paste0(tmpdir,"/data/"), verbose = TRUE)

# delete data again
fs::dir_delete(paste0(tmpdir,"/data/"))


chris-prener/compStatR documentation built on Jan. 25, 2024, 10:03 p.m.