-
Notifications
You must be signed in to change notification settings - Fork 29
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
Attempt to add number of downloads in the past year #60
Conversation
Thanks @jmanitz - off to a great start. recapparaphrasing our email earlier for posterity:
possible issues
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that changing the cached data type such that it will work with the scoring function should resolve the vignette problems (might still have that warning, though).
R/assess_downloads.r
Outdated
attr(assess_downloads_1yr,"label") <- "number of downloads in the past year" | ||
|
||
pkg_ref_cache.downloads_1yr <- function(x, name, ...) { | ||
cran_downloads(x$name, from=Sys.Date()-365, to=Sys.Date()) %>% group_by(package) %>% summarize(downloads_1yr = sum(count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea to cache the whole data.frame
that is returned by cran_downloads
since it might be useful for other download-related metrics - for example, if we have a "downloads_1yr" and "downloads_1mo", both can use the same data without downloading it twice.
pkg_ref_cache.downloads_1yr <- function(x, ...) {
cran_downloads(x$name, from=Sys.Date()-365, to=Sys.Date())
}
R/assess_downloads.r
Outdated
assess_downloads_1yr.pkg_ref <- function(x, ...) { | ||
pkg_metric(x$downloads_1yr, class = "pkg_metric_downloads_1yr") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If pkg_ref_cache.downloads_1yr
returns the whole data.frame
, we could consider the assessment as pulling the sum of the count
column.
assess_downloads_1yr.pkg_ref <- function(x, ...) {
downloads <- sum(x$downloads_1yr$count)
pkg_metric(downloads, class = "pkg_metric_downloads_1yr")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not catching this earlier but fields in x
will need to be named the same as the pkg_ref_cache
method that is used (e.g. x$downloads
when a pkg_ref_cache.downloads
is defined)
pkg_ref_cache.downloads <- function(x, ...) {
cran_downloads(x$name, from=Sys.Date()-365, to=Sys.Date())
}
#' @import cranlogs
#' @export
assess_downloads_1yr.pkg_ref <- function(x, ...) {
pkg_metric(x$downloads, class = "pkg_metric_downloads_1yr")
}
I think this change should resolve the build error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry but I guess I have to ask very stupid questions to get the stuff into the right format.
If I understand correctly you want the downloads
and download_1yr
to be separated, which makes sense so that we could have other assess functions to get 6month, rates etc.
Does that mean you want the summary of counts (sum(x$downloads_1yr$count)
) to happen later in the score
function? I would have expected it in the assess
function. Does that mean I need another assess function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries at all - this is a tricky package, and all work-in-progress code is hard to come back to after time away from the project.
This is how the code looks now (jmanitz/riskmetric R/assess_downloads.r#L17-L25)
pkg_ref_cache.downloads <- function(x, ...) {
cran_downloads(x$name, from=Sys.Date()-365, to=Sys.Date())
}
#' @import cranlogs
#' @export
assess_downloads_1yr.pkg_ref <- function(x, ...) {
pkg_metric(x$downloads_1yr, class = "pkg_metric_downloads_1yr")
}
When a field in x
is accessed (like x$downloads_1yr
), it uses the function pkg_ref_cache
to try to retrieve it based on the name. The field that you are trying to access has to match the defined pkg_ref_cache.*
method.
The problem here is that we're accessing a field called "downloads_1yr", but have defined it as pkg_ref_cache.downloads
. We just need to change x$downloads_1yr
to x$downloads
to match the pkg_ref_cache
method and we should be good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks so much for your reply. That part makes sense to me and is an easy fix. However, I think we also need to accumulate the counts in the assess function, right?
pkg_ref_cache.downloads <- function(x, ...) {
cran_downloads(x$name, from=Sys.Date()-365, to=Sys.Date())
}
#' @import cranlogs
#' @export
assess_downloads_1yr.pkg_ref <- function(x, ...) {
downloads_1yr <- sum(x$downloads$count)
pkg_metric(downloads_1yr, class = "pkg_metric_downloads_1yr")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's right - sorry for the oversight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i committed the changes as discussed, but its still buggy for list_of_pkg_ref
- can you help whats going wrong?
> pkg_ref(c("dplyr","ggplot2")) %>% assess_downloads_1yr()
Error in UseMethod("assess_downloads_1yr") :
no applicable method for 'assess_downloads_1yr' applied to an object of class "c('list_of_pkg_ref', 'vctrs_list_of', 'vctrs_vctr')"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmanitz, sorry for the delay in reviewing the changes. I think that there is just one lingering issue that needs to be resolved before we pull in the code.
R/assess_downloads.r
Outdated
assess_downloads_1yr.pkg_ref <- function(x, ...) { | ||
pkg_metric(x$downloads_1yr, class = "pkg_metric_downloads_1yr") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not catching this earlier but fields in x
will need to be named the same as the pkg_ref_cache
method that is used (e.g. x$downloads
when a pkg_ref_cache.downloads
is defined)
pkg_ref_cache.downloads <- function(x, ...) {
cran_downloads(x$name, from=Sys.Date()-365, to=Sys.Date())
}
#' @import cranlogs
#' @export
assess_downloads_1yr.pkg_ref <- function(x, ...) {
pkg_metric(x$downloads, class = "pkg_metric_downloads_1yr")
}
I think this change should resolve the build error
improvements in documentention of score function
I'm going to go ahead and pull this in. I'll make any necessary changes to get it working.
I must have missed the most recent commits. When I went to make any last changes I think everything was in good shape. Apologies for not recognizing that sooner. Thanks again @emdserono for this contribution! |
check fails because its not able to build the vignettes:
Looking into it in more detail, I am not quite sure how to resolve the following error. The vignette with that code runs through if I run it directly from Rstudio. The specific lines where the vignette fails calls the following, not sure where the gzfile is called..