Skip to content

Commit b85592d

Browse files
committed
remove the :: and ::: patterns
1 parent 5b687cb commit b85592d

14 files changed

Lines changed: 70 additions & 68 deletions

DESCRIPTION

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Authors@R: c(
66
person("Kate", "Lyons", , "k.lyons7@gmail.com", role = "ctb"),
77
person("John", "Muschelli", , "muschellij2@gmail.com", role = "ctb")
88
)
9-
Author: Gaurav Sood [aut, cre], Kate Lyons [ctb], John Muschelli [ctb]
10-
Maintainer: Gaurav Sood <gsood07@gmail.com>
119
Description: Get comments posted on YouTube videos, information on how
1210
many times a video has been liked, search for videos with particular
1311
content, and much more. You can also scrape captions from a few
@@ -31,7 +29,6 @@ Imports:
3129
mime,
3230
plyr,
3331
purrr,
34-
R6,
3532
rlang (>= 1.1.0),
3633
tibble,
3734
tidyr,

NAMESPACE

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export(yt_set_key)
7373
export(yt_set_quota_limit)
7474
export(yt_token)
7575
export(yt_topic_search)
76-
importFrom(R6,R6Class)
7776
importFrom(askpass,askpass)
7877
importFrom(checkmate,assert)
7978
importFrom(checkmate,assert_character)
@@ -91,11 +90,17 @@ importFrom(checkmate,check_character)
9190
importFrom(checkmate,check_list)
9291
importFrom(checkmate,check_null)
9392
importFrom(digest,digest)
93+
importFrom(dplyr,arrange)
9494
importFrom(dplyr,bind_rows)
95+
importFrom(dplyr,desc)
9596
importFrom(dplyr,filter)
97+
importFrom(dplyr,group_by)
9698
importFrom(dplyr,mutate)
99+
importFrom(dplyr,n)
97100
importFrom(dplyr,pull)
101+
importFrom(dplyr,rename)
98102
importFrom(dplyr,select)
103+
importFrom(dplyr,summarise)
99104
importFrom(hms,as_hms)
100105
importFrom(httr,DELETE)
101106
importFrom(httr,GET)
@@ -126,6 +131,7 @@ importFrom(httr2,resp_headers)
126131
importFrom(httr2,resp_status)
127132
importFrom(httr2,secret_decrypt)
128133
importFrom(httr2,secret_encrypt)
134+
importFrom(jsonlite,fromJSON)
129135
importFrom(jsonlite,toJSON)
130136
importFrom(magrittr,"%>%")
131137
importFrom(mime,guess_type)
@@ -146,6 +152,7 @@ importFrom(tibble,enframe)
146152
importFrom(tidyr,pivot_wider)
147153
importFrom(tidyr,unnest)
148154
importFrom(tidyr,unnest_longer)
155+
importFrom(tidyr,unnest_wider)
149156
importFrom(tidyselect,all_of)
150157
importFrom(tidyselect,everything)
151158
importFrom(utils,browseURL)

R/caching.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ generate_cache_key <- function(endpoint, query, auth) {
119119
query_str <- paste(names(query_sorted), query_sorted, sep = "=", collapse = "&")
120120

121121
key_parts <- c(endpoint, auth, query_str)
122-
cache_key <- paste0("cache_", digest::digest(key_parts, algo = "md5"))
122+
cache_key <- paste0("cache_", digest(key_parts, algo = "md5"))
123123

124124
return(cache_key)
125125
}

R/extended_endpoints.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ get_live_streams <- function(stream_id = NULL,
9494

9595
if (simplify) {
9696
result <- tryCatch({
97-
purrr::map_df(result$items, ~ flatten(.x))
97+
map_df(result$items, ~ flatten(.x))
9898
}, error = function(e) {
9999
warning("Failed to convert to data frame: ", e$message, ". Returning list format.", call. = FALSE)
100100
result
@@ -192,7 +192,7 @@ get_video_thumbnails <- function(video_id,
192192

193193
if (simplify) {
194194
result <- tryCatch({
195-
dplyr::bind_rows(thumbnail_data)
195+
bind_rows(thumbnail_data)
196196
}, error = function(e) {
197197
warning("Failed to convert to data frame: ", e$message, ". Returning list format.", call. = FALSE)
198198
thumbnail_data
@@ -282,7 +282,7 @@ get_channel_sections <- function(channel_id = NULL,
282282

283283
if (simplify) {
284284
result <- tryCatch({
285-
purrr::map_df(result$items, ~ flatten(.x))
285+
map_df(result$items, ~ flatten(.x))
286286
}, error = function(e) {
287287
warning("Failed to convert to data frame: ", e$message, ". Returning list format.", call. = FALSE)
288288
result
@@ -377,7 +377,7 @@ search_shorts <- function(query,
377377
if (simplify) {
378378
result <- tryCatch({
379379
# Convert to data frame with shorts-specific fields
380-
shorts_df <- purrr::map_df(result$items, function(item) {
380+
shorts_df <- map_df(result$items, function(item) {
381381
data.frame(
382382
video_id = item$id$videoId %||% NA_character_,
383383
title = item$snippet$title %||% NA_character_,
@@ -481,7 +481,7 @@ get_premiere_info <- function(video_id,
481481

482482
if (simplify) {
483483
result <- tryCatch({
484-
dplyr::bind_rows(premiere_data)
484+
bind_rows(premiere_data)
485485
}, error = function(e) {
486486
warning("Failed to convert to data frame: ", e$message, ". Returning list format.", call. = FALSE)
487487
premiere_data

R/get_all_channel_video_stats.R

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,30 @@ get_all_channel_video_stats <- function(channel_id = NULL, mine = FALSE, ...) {
121121
return(data.frame())
122122
}
123123

124-
# Standardize column names and add URL
124+
# Map complex column names from get_video_details to expected simple names
125125
result_df <- video_data
126126

127+
# Map column names from get_video_details output to expected names
128+
# Note: get_video_details returns flattened column names directly
129+
column_mapping <- c(
130+
"title" = "title",
131+
"publication_date" = "publishedAt",
132+
"description" = "description",
133+
"channel_id" = "channelId",
134+
"channel_title" = "channelTitle",
135+
"view_count" = "viewCount",
136+
"like_count" = "likeCount",
137+
"comment_count" = "commentCount"
138+
)
139+
140+
# Rename columns that exist
141+
for (new_name in names(column_mapping)) {
142+
old_name <- column_mapping[[new_name]]
143+
if (old_name %in% names(result_df)) {
144+
names(result_df)[names(result_df) == old_name] <- new_name
145+
}
146+
}
147+
127148
# Add video URL
128149
result_df$url <- paste0("https://www.youtube.com/watch?v=", result_df$id)
129150

@@ -132,9 +153,15 @@ get_all_channel_video_stats <- function(channel_id = NULL, mine = FALSE, ...) {
132153
"channel_id", "channel_title", "view_count", "like_count",
133154
"comment_count", "url")
134155

135-
# Select available columns
136-
available_columns <- intersect(final_columns, names(result_df))
137-
result_df <- result_df[, available_columns, drop = FALSE]
156+
# Add missing columns as NA if they don't exist
157+
for (col in final_columns) {
158+
if (!col %in% names(result_df)) {
159+
result_df[[col]] <- NA
160+
}
161+
}
162+
163+
# Select final columns in the right order
164+
result_df <- result_df[, final_columns, drop = FALSE]
138165

139166
message("Successfully retrieved data for ", nrow(result_df), " videos")
140167

R/get_channel_stats.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ list_my_channel <- function(...) {
275275

276276
# Helper function to flatten channel data to data frame
277277
flatten_channel_data <- function(items) {
278-
purrr::map_df(items, function(item) {
278+
map_df(items, function(item) {
279279
# Flatten the nested structure
280280
flat_item <- list()
281281

R/get_comment_threads.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ get_comment_threads <- function(filter = NULL, part = "snippet",
183183

184184
# Trim to actual size and combine efficiently
185185
all_items <- all_items[seq_len(item_count)]
186-
agg_res_df <- dplyr::bind_rows(lapply(all_items, as.data.frame, stringsAsFactors = FALSE))
186+
agg_res_df <- bind_rows(lapply(all_items, as.data.frame, stringsAsFactors = FALSE))
187187
# Unicode handling already applied above, no need to repeat
188188
if ("publishedAt" %in% colnames(agg_res_df)) {
189189
agg_res_df <- agg_res_df[order(agg_res_df$publishedAt), , drop = FALSE]

R/get_playlist_items.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ get_playlist_items <- function(filter = NULL, part = "contentDetails",
138138
})
139139

140140
# Combine all rows into single data.frame
141-
res <- do.call(plyr::rbind.fill, simplified_items)
141+
res <- do.call(rbind.fill, simplified_items)
142142

143143
# Add attributes to simplified result
144144
res <- add_tuber_attributes(

R/get_video_details.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# helpers for data frame conversion in `get_video_details()`
22
conditional_unnest_wider <- function(data_input, var) {
33
if (var %in% names(data_input)) {
4-
tidyr::unnest_wider(data_input, var, names_sep = "_")
4+
unnest_wider(data_input, var, names_sep = "_")
55
} else {
66
data_input
77
}
@@ -12,16 +12,16 @@ utils::globalVariables(c("kind", "etag", "items", "snippet"))
1212

1313
json_to_df <- function(res) {
1414
intermediate <- res %>%
15-
tibble::enframe() %>%
16-
tidyr::pivot_wider() %>%
17-
tidyr::unnest(cols = c(kind, etag)) %>%
15+
enframe() %>%
16+
pivot_wider() %>%
17+
unnest(cols = c(kind, etag)) %>%
1818
# reflect level of nesting in column name
19-
dplyr::rename(response_kind = kind, response_etag = etag) %>%
20-
tidyr::unnest(items) %>%
21-
tidyr::unnest_wider(col = items) %>%
19+
rename(response_kind = kind, response_etag = etag) %>%
20+
unnest(items) %>%
21+
unnest_wider(col = items) %>%
2222
# reflect level of nesting in column name for those that may not be unique
23-
dplyr::rename(items_kind = kind, items_etag = etag) %>%
24-
tidyr::unnest_wider(snippet)
23+
rename(items_kind = kind, items_etag = etag) %>%
24+
unnest_wider(snippet)
2525

2626
intermediate_2 <- intermediate %>%
2727
# fields that may not be available:
@@ -184,7 +184,7 @@ get_video_details <- function(video_ids,
184184

185185
if (simplify) {
186186
raw_res <- tryCatch({
187-
purrr::map_df(raw_res$items, ~ flatten(.x))
187+
map_df(raw_res$items, ~ flatten(.x))
188188
}, error = function(e) {
189189
warn("Failed to convert to data frame",
190190
message = e$message,
@@ -263,7 +263,7 @@ get_video_details <- function(video_ids,
263263

264264
if (simplify) {
265265
result <- tryCatch({
266-
purrr::map_df(result$items, ~ flatten(.x))
266+
map_df(result$items, ~ flatten(.x))
267267
}, error = function(e) {
268268
warn("Failed to convert to data frame",
269269
message = e$message,

R/helper_functions.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,21 @@ analyze_trends <- function(search_terms,
384384

385385
# Combine all results
386386
if (length(all_results) > 0) {
387-
combined_data <- dplyr::bind_rows(all_results)
387+
combined_data <- bind_rows(all_results)
388388

389389
# Calculate trend metrics
390390
trend_summary <- combined_data %>%
391-
dplyr::group_by(search_term) %>%
392-
dplyr::summarise(
393-
total_videos = dplyr::n(),
391+
group_by(search_term) %>%
392+
summarise(
393+
total_videos = n(),
394394
avg_views = mean(view_count, na.rm = TRUE),
395395
total_views = sum(view_count, na.rm = TRUE),
396396
avg_engagement = mean(like_count / pmax(view_count, 1), na.rm = TRUE),
397397
top_video_views = max(view_count, na.rm = TRUE),
398398
trending_score = log10(total_views + 1) * avg_engagement * 100,
399399
.groups = "drop"
400400
) %>%
401-
dplyr::arrange(dplyr::desc(trending_score))
401+
arrange(desc(trending_score))
402402

403403
result <- list(
404404
detailed_results = combined_data,

0 commit comments

Comments
 (0)