cs_prep_year: Prepare Raw Data

Description Usage Arguments Value Examples

View source: R/create.R

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

1
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

 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
# 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/"))

compstatr documentation built on July 8, 2020, 7:34 p.m.