-
Notifications
You must be signed in to change notification settings - Fork 94
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
documentation only loaded for packages named in a library() call, not with p_load() #257
Comments
Currently, we only capture explicit calls of There could be many ways to not use load_pkgs <- function() {
library(pkg1)
library(pkg2)
} we don't handle such cases at the moment. |
It looks like In fact, there's a good use case of nested suppressPackageStartupMessages({
library(data.table)
library(xml2)
}) I'll think about this. |
For what it's worth, here is my use case.
Or, if I only need to use a function once or twice in a project, With the first scenario, I cannot get any auto-complete or on-hover documentation. I know it is a lot to ask, |
@chunyunma I've actually seen some posts by the RStudio team about this and Also as someone who's taught a lot of students who were very non-tech people R I would say the import method is in and of itself far more confusing than simply teaching students to read the line in the console that says "Function X from package Y has been masked by loading package Z". If just reading that line is too confusing for them then I can't see piling environments on top of everything helping. Especially since it's really just an overcomplicated way of doing If you really want continue to teach something that anti-canonical I'd recommend at least using something like the Box package which is intended to work this way, rather than a homemade kludge. It's a more comprehensive solution and you'll be less likely to run into any headaches down the road because it was designed to work that way from the ground up. |
@D3SL Thank you for introducing me to the |
There are actually a few related issues
Above loads the package because we are only search for the
This will import the package |
I guess one solution is to check some kind of annotations in the file. Something like
or even use Roxygen tags directly
|
I file a PR #452 to support customizable unscoped functions (e.g. @D3SL @wdiao-zju Would you like to have try via remotes::install_github("REditorSupport/languageserver#452") |
It is awesome. but It only work when load single package, however, it can not work when load multiple packages using p_load. e.g. pacman::p_load(readr, ggplot2) |
Didn't know it could do this. Let me find a way to make it work. |
great, this patch works for me when using |
The specification of the unscoped functions and library functions are more flexible via 73f79d5. An unscoped function is associated with a character vector of arguments to capture so that each argument is regarded to be evaluated in the current scope. An example is A library function specification now has the full flexibility to handle how to extract the package names given the call in the document. For example, "pacman::p_load" = function(call) {
fun <- if (requireNamespace("pacman")) pacman::p_load else
function(..., char, install = TRUE,
update = getOption("pac_update"),
character.only = FALSE) NULL
call <- match.call(fun, call, expand.dots = FALSE)
if (!isTRUE(call$character.only)) {
vapply(call[["..."]], as.character, character(1L))
}
} Now it supports the following: suppressPackageStartUpMessages({
tryCatch(pacman::p_load(readr, ggplot2), error = function(e) stop("Error"))
}) |
A bug that exists for quite a while in |
The bug is fixed and please test against the latest PR and let me know if there is anything not working properly. |
Great work. I found a minor bug and it doesn't matter. pacman::p_load(p1, p2, p3) is good. But it not work when I first library(pacman) then p_load(p1, p2, p3) |
If you really need options(languageserver.library_functions = list(
p_load = function(call) {
fun <- if (requireNamespace("pacman")) pacman::p_load else
function(..., char, install = TRUE,
update = getOption("pac_update"),
character.only = FALSE) NULL
call <- match.call(fun, call, expand.dots = FALSE)
if (!isTRUE(call$character.only)) {
vapply(call[["..."]], as.character, character(1L))
}
}
) |
I wanted to test this out some but unfortunately I'm still having the issue with enormous floods of processes being opened and it makes VSCode unusable for me. Trying to do anything results in gigabytes of memory being eaten by dozens of spurious processes. It's forced me to go back to RStudio, which is unfortunate because I'm starting to really think their de facto monopoly on the entire R ecosystem is getting destructive as more and more packages become "opinionated" about doing things only according to their exact manual of style with their proprietary products. |
This might be the languageserver package itself, but I only get on-hover documentation for commands from packages loaded using
library()
rather thanpacman::p_load()
.The text was updated successfully, but these errors were encountered: