Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reply detox #111

Merged
merged 21 commits into from
Feb 16, 2021
Merged

Reply detox #111

merged 21 commits into from
Feb 16, 2021

Conversation

maxheld83
Copy link
Contributor

tracking as draft until it's ready

@njahn82
Copy link
Collaborator

njahn82 commented Feb 15, 2021

Is somehow ready

@njahn82 njahn82 added this to the MPDL Test milestone Feb 15, 2021
@maxheld83 maxheld83 marked this pull request as ready for review February 16, 2021 09:13
@@ -10,7 +10,7 @@
get_cr_md <- function(dois, .progress = "text") {
checkmate::assert_character(dois, any.missing = FALSE, unique = TRUE)
tt <- rcrossref::cr_works(dois = dois, .progress = .progress)[["data"]]
if (!is.null(tt)) {
if (nrow(tt) != 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the function not length-stable, but we'll fix these APIs later.
Length-stably, get_cr_md() should either return a df with 0 rows, or it should throw an error if we think that it makes more sense (I'd lean towards error).
In that case, the responsibility to pass on dois which actually have metadata on cr falls to upstream functions (as in biblids).

Anyway, this hotfixes #113 for now.

R/email.R Outdated
Comment on lines 76 to 90
md_data_attachment <- function(.md = NULL, session_id = NULL, dois = NULL) {
if(is.null(.md))
stop("No Crossref Data")
excel_spreadsheet <- list(`Übersicht` = .md$cr_overview,
`CC-Lizenzen` = .md$cc_license_check)
if (!is.null(.md$cr_tdm)) {
excel_spreadsheet[["TDM"]] <- .md$tdm
}
if (!is.null(.md$cr_funder)) {
excel_spreadsheet[["Förderinformationen"]] <- .md$funder_info
}
if (!length(tolower(dois) %in% tolower(.md$cr_overview$doi)) > 0)
excel_spreadsheet[["Nicht-indexierte DOIs"]] <- tibble::tibble(
mutate(missing_dois = !tolower(dois) %in% tolower(.md$cr_overview$doi))
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a bit hard to check/maintain because:

  • the function makes unexplicated/untested assumptions about the inner structure of .md (i.e. if .md$funder_info were renamed, it would break)
  • the conditionals aren't very expressive; we don't really mean that !is.null() is a very special case, we just generally mean that empty sheets shouldn't be included
  • the calculation of missing dois doesn't really belong in here.

I'll refactor this to show what I mean.
Hope that makes sense.

R/metrics_cc.R Outdated
#'
#' @inheritParams metrics_overview
#'
#' @importFrom dplyr count mutate rename
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are generally not necessary when using dplyr::mutate().
I think @importFrom statements in the roxygen blocks for individual functions is also a bit confusing/misleading, because the resulting NAMESPACE directives actually affect the entire package.

So, I think when it comes to using functions from other packages, there's basically two scenarios:

  1. If a lot of our functions use, say, pkg::foo(), then we should declare @importFrom pkg foo once in metacheck.R (conventionally used for that purpose)
  2. If only one/few of our functions use, say pkg::bar(), then should simply always use pkg::bar(), and never @importFrom.

For dplyr etc., I think it's 1. We're using that all over the place, and I have @import it in #69, which I'll merge in here.
@importing from other packages, there

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some style guides are discouraging use of the @import tag. https://google.github.io/styleguide/Rguide.html#qualifying-namespaces , but can follow the above scenarios.

R/metrics_cc.R Outdated
Comment on lines 10 to 47
cc_metrics <- function(.md = NULL, .gt = TRUE, .color = "#F3A9BB") {
if(is.null(.md) || !"cc_license_check" %in% names(.md))
stop("No CC compliance data provided, get data using cr_compliance_overview()")
else
out <- .md$cc_license_check %>%
dplyr::count(cc_norm, name = "value") %>%
dplyr::mutate(prop = value /sum(value) * 100) %>%
dplyr::rename(name = cc_norm)
if(.gt == FALSE)
out
else
ind_table_to_gt(out, prop = prop, .color = .color)
}

#' CC compliance metrics overview
#'
#' Presents the result of the CC compliance check (absolute and relative)
#'
#' @seealso [license_check()]
#'
#' @inheritParams metrics_overview
#'
#' @importFrom dplyr count mutate rename
#'
#' @export
cc_compliance_metrics <- function(.md = NULL, .gt = TRUE, .color = "#A0A5A9") {
if(is.null(.md) || !"cc_license_check" %in% names(.md))
stop("No compliance overview data provided, get data using cr_compliance_overview()")
else
out <- .md$cc_license_check %>%
dplyr::count(check_result, name = "value") %>%
dplyr::mutate(prop = value /sum(value) * 100) %>%
dplyr::rename(name = check_result)
if(.gt == FALSE)
out
else
ind_table_to_gt(out, prop = prop, .color = .color)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seems to be some duplication here the funs are not type (?) / length-stable.
will probably address that later.

@maxheld83 maxheld83 merged commit 4c932d1 into main Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_cr_md fails when no records were found remove outdated cc license check fxn
2 participants