suggestion for new feature
Often we specify names of variables in a data frame, for example when running
lm(oneLongName~anOtherLongName,data=dataframe) (coxph, glm, ...)
myfunction(dataframe, y~x1)
I was wondering if a tab completion function could be constructed to recognize the name of an existing dataframe inside a function call (much like the help that reads off the object type) so that we do not have to type the sometimes difficult variable names. We might not have typed all parenthesis as in the above two function calls, but maybe we have written the dataframe in the same line.
Thanks for Nvim !!
If you run R in Neovim's built-in terminal, the R output will be in another buffer and everything there will be available for keyword completion. You have just to press \rn over the data.frame once to get the list of column names. If you run R in an external application (terminal emulator, tmux pane, Rgui, or Rapp), the names of columns can be displayed in the Object Browser (\ro) and, consequently, be available for keyword completion.
That is right ! I think the issue is perhaps the way the tab-completion has the names ordered, I have just gone \rn over a data frame and now recall the names and now want to do a tab completion with some names, now in tab-list i see many many names and I can not see which names are associated with what data-frame.
thanks and best
@scheike: Not sure if I got what you are looking for, but maybe https://github.com/gaalcaras/ncm-R has what you need?
ncm-R does not support this feature at the moment. Actually, RStudio doesn't either and I think there is a good reason for that.
The problem is, R functions deal with this kind of arguments in a variety of ways: sometimes it's lm(formula, data = df), sometimes it's subset(x, ...) and so on. That means we'd have to check for many different cases, and at times check for code after the cursor position which might complicate things even more. The trade off is not ideal, as completion could get slower only to address a few isolated cases.
If you really need completion inside lm() and you're not averse to pipes, you could use them to benefit from variable completion inside data pipelines:
library(nycflights13)
data(flights)
flights %>%
lm(dep_delay ~ month, data = .)
It does look a bit weird... but completion will work in RStudio or with ncm-R.
Dear Gabriel,
thanks ! As far as I can see the dplyr example you show is indeed the functionality that I'm after, except I thought it could be useful for many other settings. I understand that the search order needs to be choosen. Using for example the latest data-frames and their variables would be a simple way to do this (??). Typically, we work on specific data-set and then do several analyses with this.
Thanks for all for considering this.
best regards
From: Gabriel Alcaras [[email protected]] Sent: Friday, December 15, 2017 12:50 AM To: jalvesaq/Nvim-R Cc: Thomas Scheike; Mention Subject: Re: [jalvesaq/Nvim-R] suggestion for new feature (#249)
ncm-Rhttps://github.com/gaalcaras/ncm-R does not support this feature at the moment. Actually, RStudio doesn't either and I think there is a good reason for that.
The problem is, R functions deal with these kind of arguments in a variety of ways: sometimes it's lm(formula, data = df), sometimes it's subset(x, ...) and so on. That means we'd have to check for many different cases, and at times check for code after the cursor position which might complicate things even more. The trade off is not ideal, as completion could get slower only to address a few isolated cases.
If you really need completion inside lm() and you're not averse to pipeshttps://www.fromthebottomoftheheap.net/2015/06/03/my-aversion-to-pipes/, you could use them to benefit from variable completion inside data pipelines:
library(nycflights13) data(flights)
flights %>% lm(dep_delay ~ month, data = .)
It does look a bit weird... but completion will work in RStudio or with ncm-R.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/jalvesaq/Nvim-R/issues/249#issuecomment-351871325, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJvzwOB8gQ7ApGI5uWMQAwOcHqpGHrM9ks5tAbRBgaJpZM4QkHVM.
I'm not sure this solves your problem, but it can cut down on writing out formulas + you don't have to remember any names (other than your target ).
data(iris)
n <- names(iris)
f <- as.formula(paste("Sepal.Length ~", paste(n[!n %in% "Sepal.Length"], collapse = " + ")))
# Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species
fit <- lm(f, iris)
@beigebrucewayne A dot in a formula means "all other variables". So, we get the same result with:
data(iris)
fit <- lm(Sepal.Length ~ ., iris)
@jalvesaq Haha, true true -1 for my overly clever nonsense.
The options R_fun_data_1 and R_ fun_data_2 allow something close to what was requested, although not as good.