emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
614 stars 160 forks source link

feature request: automatically add library(...) expressions, or offer to add them #1168

Closed torbjorn closed 2 years ago

torbjorn commented 2 years ago

Suppose I write an R script, and enter eg.

iris %>% filter( Sepal.Length > 5 )

I would like ess to now realise that %>% is not part of base, but I often access this operator from the dplyr package (or tidyverse), and ess would go on to offer to add library(dplyr) in the top of my script after other library statements.

It could even prompte me to choose from good candidates, perhaps with a default based on previous choices, or just go straight for the most common library I use to acces this operator

The same would go for functions from packages too.

Would this be too invasive, or prone to getting it wrong anyway? I know I find it a little annoying to go up to the buffer and add libraries as I use more and more functionality in an R file.

lionel- commented 2 years ago

Such a feature would be a big project on its own. And so best implemented in a third-party package.

And unfortunately there's a severe lack of Emacs Lisp developers in the community, so if you want a feature you will likely have to write it yourself... Especially large features like this.

vspinu commented 2 years ago

Such a feature exists in lsp for other languages. It's called source.organizeImports action (see lsp-organize-imports). It's not implemented in R language server. You can try pushing it there.

torbjorn commented 2 years ago

thanks for the info, it's beyond my capabilities for the moment, but it's good to know.

On Fri, Jan 28, 2022 at 8:34 PM Vitalie Spinu @.***> wrote:

Such a feature exists in lsp for other languages. It's called source.organizeImports action (see lsp-organize-imports). It's not implemented in R language server. You can try pushing it there.

— Reply to this email directly, view it on GitHub https://github.com/emacs-ess/ESS/issues/1168#issuecomment-1024542723, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABAD3KUEHYALN3VM7HZQTUYLVURANCNFSM5HWPUW7A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- mvh Torbjørn Lindahl