Skip to content

Commit

Permalink
cat
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosell authored Dec 28, 2023
1 parent fcad437 commit e8a4767
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions functions.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,8 @@
print("functions.R")
cat("functions.R\n")

test_read <- function() {
raw <- readr::read_csv("https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2013.csv")
raw |> janitor::clean_names()
}
# 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 All @@ -53,9 +12,7 @@ clean_unemp <- function(unemp_data,

# This is a helper function to clean the data
clean_data <- function(x){
print("clean_data")
print("str")
print(str(x))
cat("clean_data\n")
x |>
janitor::clean_names() |>
mutate(level = case_when(
Expand All @@ -78,7 +35,7 @@ clean_data <- function(x){

# This reads in the data.
get_data <- function(){
print("unemp_data")
cat("get_data\n")
urls <- list(
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2013.csv",
"https://raw.githubusercontent.com/b-rodrigues/modern_R/master/datasets/unemployment/unemp_2014.csv",
Expand All @@ -94,6 +51,7 @@ get_data <- function(){

# This plots the data
make_plot <- function(data){
cat("make_plot\n")
ggplot(data) +
geom_col(
aes(
Expand Down

0 comments on commit e8a4767

Please sign in to comment.