Skip to content

Commit

Permalink
Merge pull request #95 from ropensci-review-tools/cache
Browse files Browse the repository at this point in the history
add 'pkgmatch_update_cache' fn for #92
  • Loading branch information
mpadge authored Jan 16, 2025
2 parents 633164d + 109072e commit 0b0bec8
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pkgmatch
Title: Find R Packages Matching Either Descriptions or Other R Packages
Version: 0.4.3.001
Version: 0.4.3.002
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(pkgmatch_load_data)
export(pkgmatch_similar_fns)
export(pkgmatch_similar_pkgs)
export(pkgmatch_treesitter_fn_tags)
export(pkgmatch_update_cache)
export(pkgmatch_update_data)
export(set_ollama_url)
export(text_is_code)
Expand Down
43 changes: 41 additions & 2 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
#' idfs <- pkgmatch_load_data ("idfs")
#' idfs_fns <- pkgmatch_load_data ("idfs", fns = TRUE)
#' }
pkgmatch_load_data <- function (what = "embeddings", corpus = "ropensci",
fns = FALSE, raw = FALSE) {
pkgmatch_load_data <- function (what = "embeddings",
corpus = "ropensci",
fns = FALSE,
raw = FALSE) {

checkmate::assert_character (what, len = 1L)
checkmate::assert_character (corpus, len = 1L)
Expand All @@ -55,6 +57,43 @@ pkgmatch_cache_update_interval <- function () {
return (dt)
}

# nocov start

#' Update all locally-cached `pkgmatch` data to latest versions.
#'
#' Locally-cached data used by this package are generally updated every 30
#' days, or according to `options("pkgmatch_update_frequency")` if that is set.
#' This function forces all locally-cached data to be updated, regardless of
#' update frequencies. Remote data are provided on the latest release of GitHub
#' repository at
#' \url{https://github.com/ropensci-review-tools/pkgmatch/releases}.
#'
#' @examples
#' \dontrun{
#' pkgmatch_update_cache()
#' }
#' @export
pkgmatch_update_cache <- function () {

what <- c ("embeddings", "idfs", "functions", "calls")
corpus <- c ("ropensci", "cran")
fns <- c (FALSE, TRUE)
raw <- c (FALSE, TRUE)

vals <- expand.grid (what = what, corpus = corpus, fns = fns, raw = raw)
vals$fname <- apply (vals, 1, function (i) {
get_cache_file_name (what = i [1], corpus = i [2], fns = i [3], raw = i [4])
})
vals <- vals [-which (duplicated (vals$fname)), ]

files <- apply (vals, 1, function (i) {
pkgmatch_dl_data (what = i [1], corpus = i [2], fns = i [3], raw = i [4])
})

invisible (files)
}
# nocov end

load_data_internal <- function (what, corpus, fns, raw) {
fname <- get_cache_file_name (what, corpus, fns, raw)

Expand Down
6 changes: 6 additions & 0 deletions R/data-update.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ RELEASE_TAG <- "v0.4.0"
#' "pkgmatch-results" of R's current temporary directory. This updating may
#' take a very long time!
#'
#' Note that this function is categorically different from
#' \link{pkgmatch_update_cache}. This function updates the internal data used
#' by the `pkgmatch` package, and should only ever be run by package
#' maintainers. The \link{pkgmatch_update_cache} downloads the latest versions
#' of these data to a local cache for use in this package.
#'
#' @param upload If `TRUE`, upload updated results to GitHub release.
#' @return Local path to directory containing updated results.
#' @family data
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/pkgmatch",
"issueTracker": "https://github.com/ropensci-review-tools/pkgmatch/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.4.3.001",
"version": "0.4.3.002",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
21 changes: 21 additions & 0 deletions man/pkgmatch_update_cache.Rd

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

7 changes: 7 additions & 0 deletions man/pkgmatch_update_data.Rd

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

0 comments on commit 0b0bec8

Please sign in to comment.