Skip to content

Commit

Permalink
mark stale_package_check for deprecation (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Dec 29, 2024
1 parent cb8d8e5 commit 6cedb4c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

I tried looking around GitHub for existing users, but if this affects you, please don't hesitate to file a FR and I can restore anything deleted too hastily.

* `stale_package_check()` is also deprecated. Prefer using `lintr::unused_import_linter()` instead. {lintr} will have better maintenance, reliability, and correctness.

* `get_age()` got some substantial improvements.
+ Gives the right age in some cases, e.g. 7 1/366 years for someone born Dec. 22, 2024 as of Dec. 23, 2031 (#23). Accuracy is now confirmed for a full grid of >2 million possible birthday, age combinations.
+ Implementation is improved for about 2x speed-up. This was in service of making the implementation friendlier for static translation to other execution engines (in particular {arrow}, #18). Thanks @TPDeramus for the request and @jonkeane for consulting on acero particulars.
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ get_all_plain_calls = function(e) {
# packages loaded are actually used
#' @param con A connection
stale_package_check = function(con) {
warning("This function is deprecated. Use lintr::unused_import_linter() instead")
code = tryCatch(parse(con), error = identity)
if (inherits(code, 'error')) {
cat('Failed to parse R script, please fix syntax errors first\n')
Expand Down
2 changes: 1 addition & 1 deletion man/funchir-utils.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
\item{dates}{ A vector of \code{Date}s. }
}
\value{
\code{stale_package_check} reads a file (with \code{\link{readLines}}) and checks which functions are actually used from each loaded package. Currently only checks for \code{library} (i.e., not \code{require}) calls.
\code{stale_package_check} (DEPRECATED in favor of lintr::unused_import_linter) reads a file (with \code{\link{readLines}}) and checks which functions are actually used from each loaded package. Currently only checks for \code{library} (i.e., not \code{require}) calls.

\code{embed.mat} inserts a supplied matrix into a (weakly) larger enclosing matrix, typically filled with 0s, at a specified position.

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that('stale_package_check works', {
stale_package_path <- function(path) test_path('stale_package_test_scripts', path)

expect_output(
stale_package_check(stale_package_path('simple.R')),
expect_warning(stale_package_check(stale_package_path('simple.R')), "lintr::unused_import_linter"),
paste(
c("Functions matched from package stats:",
paste0("\t", toString(sort(c("density", "rnorm")))),
Expand All @@ -15,19 +15,19 @@ test_that('stale_package_check works', {
)

expect_output(
stale_package_check(stale_package_path('use_namespace_call.R')),
expect_warning(stale_package_check(stale_package_path('use_namespace_call.R')), "lintr::unused_import_linter"),
'**No exported functions matched from stats**',
fixed = TRUE
)

expect_output(
stale_package_check(stale_package_path('wont_parse.R')),
expect_warning(stale_package_check(stale_package_path('wont_parse.R')), "lintr::unused_import_linter"),
'Failed to parse R script, please fix syntax errors first',
fixed = TRUE
)

expect_output(
stale_package_check(stale_package_path('no_library.R')),
expect_warning(stale_package_check(stale_package_path('no_library.R')), "lintr::unused_import_linter"),
'No library() or require() calls found',
fixed = TRUE
)
Expand Down

0 comments on commit 6cedb4c

Please sign in to comment.