Skip to content

Commit

Permalink
Merge pull request #94 from ropensci-review-tools/cran
Browse files Browse the repository at this point in the history
Fix update functions to close #92
  • Loading branch information
mpadge authored Jan 16, 2025
2 parents 857d8ad + 872ce02 commit 633164d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
on:
push:
branches:
- main
# push:
# branches:
# - main
schedule:
- cron: 0 0 * * 1
- cron: 1 0 * * *

name: Update pkgmatch data

Expand Down
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.2.025
Version: 0.4.3.001
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
8 changes: 8 additions & 0 deletions R/data-update-cran.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pkgmatch_update_cran <- function () {
fs::file_delete (tarball_path)
}

# This is necessary because `utils::untar()` can create hanging
# connections:
closeAllConnections ()

pkgmatch_update_progress_message (p, 1, npkgs, pt0)

return (dat)
Expand Down Expand Up @@ -85,6 +89,10 @@ dl_one_tarball <- function (results_path, tarball) {
httr2::req_perform (req),
error = function (e) NULL
)
# path <- tryCatch (
# curl::curl_download (url, destfile = path),
# error = function (e) NULL
# )

if (is.null (resp)) {
return (NULL)
Expand Down
24 changes: 23 additions & 1 deletion R/data-update-ropensci.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ pkgmatch_update_ropensci <- function () {
extract_data_from_local_dir (pkg_dir),
error = function (e) NULL
)
fns <- tryCatch (
pkgmatch_embeddings_from_pkgs (pkg_dir, functions_only = TRUE),
error = function (e) NULL
)
fs::dir_delete (pkg_dir)

pkgmatch_update_progress_message (i, 1, nrow (reg_updated), pt0)

return (dat)
return (list (dat = dat, fns = fns))
})
fns <- do.call (cbind, lapply (res, function (i) i$fns))
res <- lapply (res, function (i) i$dat)
names (res) <- reg_updated$name

append_data_to_embeddings (res, flist, cran = FALSE)
append_data_to_bm25 (res, flist, cran = FALSE)
append_data_to_fn_calls (res, flist, cran = FALSE)

append_data_to_fn_embeddings (fns, flist)

options ("rlib_message_verbosity" = op)

return (TRUE)
Expand Down Expand Up @@ -94,3 +102,17 @@ days_in_this_month <- function (today = Sys.Date ()) {
dates <- seq (this_month, next_month, by = "day")
return (length (dates) - 1L)
}

append_data_to_fn_embeddings <- function (fns, flist) {

pkgs <- unique (gsub ("::.*$", "", colnames (fns)))
f <- grep ("embeddings\\-fns\\.", flist, value = TRUE)
embeddings_fns <- readRDS (f)
ptn <- paste0 (paste0 (pkgs, "::"), collapse = "|")
index <- which (!grepl (ptn, colnames (embeddings_fns)))
embeddings_fns <- cbind (embeddings_fns [, index], fns)

index <- order (colnames (embeddings_fns))
embeddings_fns <- embeddings_fns [, index]
saveRDS (embeddings_fns, f)
}
4 changes: 2 additions & 2 deletions R/similar-fns.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ pkgmatch_similar_fns <- function (input, embeddings = NULL, n = 5L, browse = FAL
stopifnot (!is.null (nms))
stopifnot (all (grepl ("\\:\\:", nms)))

op <- options ()
op <- getOption ("rlib_message_verbosity")
options (rlib_message_verbosity = "quiet")
emb <- get_embeddings (input)
options (op)
options (rlib_message_verbosity = op)

res <- cosine_similarity (emb [, 1], embeddings)
res$rank <- seq_len (nrow (res))
Expand Down
4 changes: 2 additions & 2 deletions R/similar-pkgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ similar_pkgs_from_pkg <- function (input, embeddings) {

similar_pkgs_from_pkg_internal <- function (input, embeddings) {

op <- options ()
op <- getOption ("rlib_message_verbosity")
options (rlib_message_verbosity = "quiet")

emb <- pkgmatch_embeddings_from_pkgs (input)

options (op)
options ("rlib_message_verbosity" = op)

d_text <- lapply (
c ("text_with_fns", "text_wo_fns"),
Expand Down
4 changes: 2 additions & 2 deletions 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.2.025",
"version": "0.4.3.001",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -407,7 +407,7 @@
},
"SystemRequirements": {}
},
"fileSize": "492.3KB",
"fileSize": "2839.819KB",
"readme": "https://github.com/ropensci-review-tools/pkgmatch/blob/main/README.md",
"contIntegration": [
"https://github.com/ropensci-review-tools/pkgmatch/actions?query=workflow%3AR-CMD-check",
Expand Down

0 comments on commit 633164d

Please sign in to comment.