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

Sort results by date (@) #118

Closed
wleoncio opened this issue Sep 28, 2023 · 7 comments
Closed

Sort results by date (@) #118

wleoncio opened this issue Sep 28, 2023 · 7 comments

Comments

@wleoncio
Copy link

I often use pkgsearch to look up package submissions by me and my colleagues for our centre's monthly report. For that reason, it would be very useful for us to have the results of advanced_search() ordered by date instead of the default (score?).

I was about to submit a PR with a suggestion to add a sort_by parameter to the summary.pkg_search_result() method (maybe print() too?), but before putting in the work I'd like to check with you if that's something you're interested in seeing added to the package.

@gaborcsardi
Copy link
Contributor

You can just order according to the date column, no?

❯ pkgsearch::pkg_search("testing") |> dplyr::arrange(desc(date))
- "testing" ---------------------------------- 2323 packages in 0.015 seconds -
  #     package  version by                               @ title
  1  16 vdiffr   1.0.6   Lionel Henry                    1M Visual Regressio...
  2 100 testthat 3.1.10  Hadley Wickham                  3M Unit Testing for R
  3   8 httptest 4.2.1   Neal Richardson                 4M A Test Environme...
  4  57 covr     3.6.2   Jim Hester                      6M Test Coverage fo...
  5  16 tinytest 1.4.1   Mark van der Loo                7M Lightweight and ...
  6  10 moments  0.14.1  Lukasz Komsta                   1y Moments, Cumulan...
  7  15 lmtest   0.9.40  Achim Zeileis                   2y Testing Linear R...
  8   8 lmerTest 3.1.3   Rune Haubo Bojesen Christensen  3y Tests in Linear ...
  9  12 RUnit    0.4.32  Roman Zenka                     5y R Unit Test Fram...
 10   9 nortest  1.0.4   Uwe Ligges                      8y Tests for Normality

Of course this does not mean that you are getting the latest 10 packages. Rather, it is the 10 packages with the highest rank, ordered by date.

@wleoncio
Copy link
Author

Yep, that works, but I'd rather avoid the piping and the dplyr dependency. Perhaps it's just me? 😅

@gaborcsardi
Copy link
Contributor

I am pretty sure that you can sort a data frame without piping and dplyr, though, no?

@wleoncio
Copy link
Author

wleoncio commented Sep 28, 2023

Yeeeah, but at least when I do it that wat, i.e. treating the search output as a data.frame object, print formatting gets lost.

There's probably a smarter way to do this (using with(), perhaps?), but this is the most base-R way I know how to do this:

x <- pkgsearch::pkg_search("testing")
x[order(x$date, decreasing = TRUE)

The second operation causes x to lose its pkg_search_result class, which results in bypassing its print() method.

@gaborcsardi
Copy link
Contributor

This seems to work:

x <- pkgsearch::pkg_search("testing")
x[] <- x[order(x$date, decreasing = TRUE), ]
x
- "testing" ---------------------------------- 2323 packages in 0.011 seconds -
  #     package  version by                               @ title
  1  16 vdiffr   1.0.6   Lionel Henry                    1M Visual Regressio...
  2 100 testthat 3.1.10  Hadley Wickham                  3M Unit Testing for R
  3   8 httptest 4.2.1   Neal Richardson                 4M A Test Environme...
  4  57 covr     3.6.2   Jim Hester                      6M Test Coverage fo...
  5  16 tinytest 1.4.1   Mark van der Loo                7M Lightweight and ...
  6  10 moments  0.14.1  Lukasz Komsta                   1y Moments, Cumulan...
  7  15 lmtest   0.9.40  Achim Zeileis                   2y Testing Linear R...
  8   8 lmerTest 3.1.3   Rune Haubo Bojesen Christensen  3y Tests in Linear ...
  9  12 RUnit    0.4.32  Roman Zenka                     5y R Unit Test Fram...
 10   9 nortest  1.0.4   Uwe Ligges                      8y Tests for Normality

@gaborcsardi
Copy link
Contributor

In any case, my point is, it does not seems like a good solution to add a sort_by argument to every function that creates a data frame. It is much better to leave this to other tools, then you can easily sort according to multiple fields, in increasing/decreasing order, using various locales, etc.

Many people use dplyr or data.table for manipulating data frames, so this is very easy for them, and if you need a no-dependency approach, that is also easy enough.

In this particular case a sort_by argument is also not so great because it suggests that pkgsearch would return the last 10 (or size) results according to release date, but that is obviously not true.

Btw. there is probably a better way to query what you want. pkgsearch is good at ranking the results, but that's not what you need here. E.g. you could use tools::CRAN_package_db().

@wleoncio
Copy link
Author

Fair enough, thank you for the productive discussion! :)

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

No branches or pull requests

2 participants