Skip to content

Commit

Permalink
2 new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc committed Mar 10, 2024
1 parent 77b1c3b commit 0ef9fe5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(batch_pubmed_download2)
export(check_pubmed_api_token)
export(clean_journals_continents)
export(convert_hex_to_char)
export(detect_missing_journals)
export(dygraph_year)
export(extract_split_address)
export(get_affiliation)
Expand All @@ -26,6 +27,7 @@ export(table_continent_year)
export(table_country)
export(table_country_journal)
export(table_country_year)
export(table_journal_count)
export(table_missing_country)
export(waffle_continent)
export(waffle_continent_journal)
Expand Down
48 changes: 42 additions & 6 deletions R/clean_journals_continents.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ clean_journals_continents <- function(data) {
field = pubmedDashboard::journal_field$field[match(
.data$journal, pubmedDashboard::journal_field$journal
)],
field = ifelse(is.na(.data$field), pubmedDashboard::journal_field$field[match(
.data$journal, pubmedDashboard::journal_field$journal_short)], .data$field),
original_journal = .data$journal %in% pubmedDashboard::journal_field$journal[1:6],
continent = factor(.data$continent, levels = continent_order()),
journal = clean_journal_names(.data$journal)
# journal = gsub(":.*", "", .data$journal),
# journal = tools::toTitleCase(.data$journal),
# journal = trimws(.data$journal),
)
) %>%
dplyr::group_by(.data$journal) %>%
dplyr::mutate(first_Year = min(.data$year), last_year = max(.data$year),
year_range = paste0(.data$first_Year, "-", .data$last_year)) %>%
dplyr::ungroup()
}

#' @noRd
Expand All @@ -28,9 +31,42 @@ continent_order <- function(short = FALSE) {

#' @noRd
clean_journal_names <- function(journal) {
x <- gsub("&amp;", "&", journal, fixed = TRUE)
x <- gsub(":.*", "", journal)
x <- gsub("&amp;", "and", journal, fixed = TRUE)
# x <- gsub(" of the United States of America", "", x, fixed = TRUE)
x <- gsub(":.*", "", x)
x <- gsub("[(].*", "", x)
x <- tools::toTitleCase(x)
trimws(x)
}

#' @title Detect missing journals
#' @param data The processed dataframe of data
#' @export
detect_missing_journals <- function(data) {
data.frame(journal = pubmedDashboard::journal_field$journal_short) %>%
dplyr::mutate(found = pubmedDashboard::journal_field$journal_short %in%
clean_journal_names(unique(data$journal))) %>%
dplyr::arrange(data$found)
}

#' @title Count number of papers per journal, with year range
#' @param data The processed dataframe of data
#' @param datatable Whether to output a [DT::datatable] HTML table widget
#' instead of a regular dataframe (defaults to TRUE).
#' @export
table_journal_count <- function(data, datatable = TRUE) {
x <- dplyr::count(data, data$journal, data$field, data$year_range, sort = TRUE) %>%
dplyr::mutate(field = stringr::str_to_title(.data$field)) %>%
as.data.frame() %>%
dplyr::rename("year range" = "year_range") %>%
dplyr::rename_with(stringr::str_to_title)
if (isTRUE(datatable)) {
insight::check_if_installed("DT")
x <- DT::datatable(
x,
options = list(searching = TRUE, paging = TRUE),
caption = "Count of journals, with year range")
}
x
}

2 changes: 1 addition & 1 deletion data-raw/journal_field.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ general <- c(
"Proceedings of the National Academy of Sciences of the United States of America",

Check warning on line 64 in data-raw/journal_field.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/journal_field.R,line=64,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 84 characters.
"Science (New York, N.Y.)",
"Nature",
"Plos one"
"PloS one"
)

journal_field <- data.frame(
Expand Down
Binary file modified data/journal_field.rda
Binary file not shown.
14 changes: 14 additions & 0 deletions man/detect_missing_journals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/table_journal_count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ef9fe5

Please sign in to comment.