Report loaded status from pkg_list#1177
Conversation
The Packages pane renders a read-only loaded indicator (filled green dot
when attached, empty ring when not) using a single new field:
loaded = paste0("package:", name) %in% search()
The pak/base/renv method branches collapse to a single
utils::installed.packages() call. renv overrides .libPaths() in an
active project, so the same call works there too. The `method`
parameter stays in the signature for RPC compatibility but is unused.
See posit-dev/positron#13184
|
This PR collapses the implementation between the three package manages into a single implementation. This was the recommendation from #1165 and it feels like a good idea. This PR is also a minimalist change so as to avoid any distractions trying to land code for the next release. So, this only focuses on the loaded prop. |
jennybc
left a comment
There was a problem hiding this comment.
I made 2 comments, but I'm happy for you to resolve and get this feature in.
| version = ip[i, "Version"], | ||
| loaded = paste0("package:", name) %in% attached_packages | ||
| ) | ||
| }) |
There was a problem hiding this comment.
I think the above produces a correct result. But similar to a suggestion in #1165, it's more idiomatic for R and its native vectorization to make these objects first. Then reshape:
ip <- utils::installed.packages()
name <- ip[, "Package"]
version <- ip[, "Version"]
id <- paste0(name, "-", version)
loaded <- paste0("package:", name) %in% search()
Map(list, id = id, name = name, displayName = name,
version = version, loaded = loaded)So, this suggestion is mostly about style, but I'll make it anyway. I guess it might even be a bit more efficient to get the %in% out of the loop, but that's not my main motivation.
| name = name, | ||
| displayName = name, | ||
| version = ip[i, "Version"], | ||
| loaded = paste0("package:", name) %in% attached_packages |
There was a problem hiding this comment.
Should we call this "attached"? I'm just thinking to head off any confusion about attached vs loaded. Because we clearly mean attached here.
I'm getting at the difference between what search() reports versus loadedNamespaces().
The Positron Packages pane renders a read-only loaded indicator (filled green dot when attached, empty ring when not) using a single new field:
The pak/base/renv method branches collapse to a single utils::installed.packages() call. renv overrides .libPaths() in an active project, so the same call works there too. The
methodparameter stays in the signature for RPC compatibility but is unused.See posit-dev/positron#13184