Skip to content

Commit

Permalink
Update functions.R
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosell authored Dec 28, 2023
1 parent 5edc43b commit 09406f5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion functions.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
# clean_unemp() is a function inside a package I made. Because I don't want you to install
# the package if you're following along, I'm simply sourcing it:
clean_unemp <- function(unemp_data,
year_of_interest = NULL,
place_name_of_interest = NULL,
level_of_interest = NULL,
col_of_interest){

if(is.null(year_of_interest)){

year_of_interest <- quo(year)

}

if(is.null(place_name_of_interest)){

place_name_of_interest <- quo(place_name)

}

if(is.null(level_of_interest)){

level_of_interest <- quo(level)

}

result <- unemp_data |>
janitor::clean_names() |>
dplyr::filter(year %in% !!year_of_interest,
place_name %in% !!place_name_of_interest,
level %in% !!level_of_interest) |>
dplyr::select(year, place_name, level, {{col_of_interest}})

if(nrow(result) == 0) {
warning("The returned data frame is empty. This is likely because the `place_name_of_interest` or `level_of_interest` argument supplied does not match any rows in the original data.")
}
result
}


source("https://raw.githubusercontent.com/b-rodrigues/myPackage/main/R/functions.R")

# The cleaned data is also available in that same package. But again, because I don't want you
# to install a package just for a blog post, here is the script to clean it.
Expand Down

0 comments on commit 09406f5

Please sign in to comment.