This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_tweet_count <- function(dat) { | |
return( | |
dat %>% | |
group_by(user_id) %>% | |
mutate( | |
tweet_count = n() | |
) %>% | |
ungroup() # to remove grouped_df class | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dat <- dat %>% | |
rowwise() %>% | |
mutate(bundesland = unlist(bundesland), | |
community = unlist(community), | |
fach = unlist(fach)) %>% | |
ungroup() # important to remove rowwise_df class! (slows down all other operations) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mutate numeric (0 / 1) coded columns to logical | |
dat <- s1 %>% | |
mutate(across(where(is.numeric), as.logical)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dat %>% select_if(is.list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Length of sublist | |
dat$media_url[sapply(dat$media_url, function(x) length(x) == 2)] | |
# not empty sublists | |
dat$media_url[sapply(dat$media_url, function(x) !is.na(x))] | |
dat$media_url[sapply(dat$media_url, function(x) all(!is.na(x)))] # multiple NA values per sublist | |
na.omit.list <- function(list) { | |
return(list[sapply(list, function(x) all(!is.na(x)))]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drake_plan( | |
# dplyr::distinct instead? | |
user_data = tidy_data %>% unique(user_id) %>% select(user_related_cols), # remove "tweet level" vars for faster runtime | |
geo_data = do_user_data_stuff(), | |
# left_join: Join matching rows from b to a. | |
joined_data = target(command = left_join(user_data, tidy_data, by = "user_id"), | |
format = "fst" # useful ??? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# needs to be outside of the drake plan for `rmd_files = !!pages_paths` to work | |
pages_paths <- dir("reports", pattern = "*.Rmd", full.names = TRUE) | |
# TODO: exclude _file.Rmd with regex in dir | |
plan <- drake_plan( | |
render_pages = target( | |
# TODO: Add a trigger dependency on _site.yml | |
command = rmarkdown::render( | |
knitr_in(rmd_files), | |
output_dir = file_out("docs/"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
codebook = file_in(URL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
date: "`r format(Sys.time(), '%d. %B, %Y')`" | |
--- |