Open lionel- opened 9 years ago
This may or may not be relevant (apologies), but one option for consistent autocompletion in Emacs and other editors could be to use the Language Server Protocol, which seems to have buy-in from RMS, and early support in Emacs.
The LSP seems to be used in Emacs for Rust already. It may be that Rstudio may be willing to convert their existing engine to an LSP implementation, or that writing a language server for R would make a good proposal for the R consortium (https://www.r-consortium.org/projects/awarded-projects). Apologies if off-topic/irrelevant.
Very interesting. Thanks!
I haven't read through this whole thread, but just stumbled on this vim plugin that auto-completes inside pipes and ggplot calls, which strikes me as not completely unreasonable: https://github.com/gaalcaras/ncm-R
I am not sure to understand all this conversation but using ess
, auto-completion
and tidyverse idiomatics as this one :
mtcars %>%
filter(cy
cyl
is not found !
Any help ?
Such completions are not implemented. I have in plan to finally work on this before the end of the year.
As a stop gap, perhaps just a separate binding to display completions for column names would be useful? A manual binding would just require finding the relevant data, without needing to analyze the proper location to complete, etc., and could be just about as useful. At least, I know I forget the column names all the time, and have to jump over to the repl to print them out.
I got another problem with autocomplete
ess
and R
.
df <- data.frame( `X 1` = 1:3 )
df$X
If I press TAB
the completion will be df$X 1
which will throw an error.
Column names with space character in them need to be autocomplete with added backquotes (RStudio does that).
The expected output :
df <- data.frame( `X 1` = 1:3 )
df$`X 1`
Honestly, according to my "book" (rather "taste"), using so-called "non syntactic" names as you do here, should not be supported by autocompletion. Autocompletion should help to use correct syntax, and "non syntactic" names are kind of an exception which makes sense, but users should typically not use ...
I think they should be supported, I expect it's little work. It doesn't make sense to expand without the quotes, I consider it a bug.
The backquote completion stuff is a duplicate of #865 I believe.
I found myself re-checking this issue after searching if any implementation was available through languageserver
. While problem-solving that I did notice that VScode also has partially addressed this issue. I just thought I'd leave a note here if it is of any interest:
There is some sort of implementation in VScode and the vscode-r plugin which performs completion of variables/columns as objects in sub environments. It is referred to in this article..
Having had a quick test, it works quite well for simplistic use cases. It seems to parse only objects stored in the global env and can suggest them to dplyr verb function arguments (eg select(col1, col2)
), and ggplot aes()
and maybe others.
It doesn't seem able to parse a pipeline live, rather, just operates on the structure of existing objects stored before a pipeline is initiated. Adding, removing columns, or starting the pipeline with a data.frame()
appears to disrupt the functionality.
It'd be great to extend the places where auto-completion works in ESS.
We could start by looking for
data = x
arguments, and look for the names inx
. This way, auto-completion would be triggered while writing formulaes inlm()
. In the following example ESS would propose "disp" and "drat":I think this kind of autocompletion should be triggered inside all subcalls, so that it'd work inside
I()
withlm()
, or insideaes()
withggplot()
.To avoid undesired side effects, we could list the arguments where this kind of completion should take place, for example the "formula" argument of
lm()
,glm()
, the "mapping" argument ofggplot()
, etc. This should be defined in a user-customisable variable.Then we should think about pipelines. ggplot and dplyr are used to such an extent in the R community that they deserve special attention. We should recognise ggplot pipelines and enable
aes()
completions based on the layer-level data if it exists, and on the top-level data otherwise.With dplyr we have the additional difficulty that the contents may change down the pipelines, so we should check the results at every step. RStudio developers achieved this with good performance by making sure that each dplyr verb works with zero-row data frames. This way we can eval the pipeline with empty data and check the output names at each step with low cost.
Vitalie, do you think the current framework could be arranged to add such new sources of completion?