Open utterances-bot opened 1 year ago
Really nice post! I have been using emacs for years, but I'm just starting to try out ESS.
Are you on twitter? I tweeted about this post here: https://twitter.com/llaisdy/status/1612569421259722753
Thanks for the comment @llaisdy, let me know if I can help you somehow or if you have some topics you'd like to see here. I do have twitter but I don't use it much, I'll add you anyway. I use Mastodon much more here @teoten@social.linux.pizza I need to update my contact etails in the blog for sure.
Thanks for the post. How did you deal with not having features from RStudio like completions for column names? I used Doom Emacs to get me started but to me Rstudio is still much better than ESS when it comes to code completion and overall running of different file types (qmd/rmd and Rscripts).
Thanks for the post. How did you deal with not having features from RStudio like completions for column names? I used Doom Emacs to get me started but to me Rstudio is still much better than ESS when it comes to code completion and overall running of different file types (qmd/rmd and Rscripts).
Hi @davidbudzynski that's probably the only "disadvantage" I see for Emacs: you have to add and configure a package for any functionality you want. On the other hand it has the "advantage" that you can add functionalities for way more things than R Studio.
Having said so, ESS uses Company for auto-completion. Once you install it and load it (either globally or locally for ESS only) all you need to do is to load the variables to the R memory (i.e., by sending it to R console from the script with C-c C-c
) and then Company will recognize it automatically and propose potential options to auto complete. Here are some examples.
I set it to show me potential object after typing 3 characters, but you can change that.
The column options are automatic after typing the $
.
And you can configure a lot of stuff in Company alone. Here is my configuration for company, the comments say what each line modifies. I have to fix that piece of code but for now it works for me.
(use-package company
:config
;; Turn on company-mode globally:
(add-hook 'after-init-hook 'global-company-mode))
;; More customization options for company:
(setq company-selection-wrap-around t
;; Align annotations to the right tooltip border:
company-tooltip-align-annotations t
;; Idle delay in seconds until completion starts automatically:
company-idle-delay 0.45
;; Completion will start after typing two letters:
company-minimum-prefix-length 3
;; Maximum number of candidates in the tooltip:
company-tooltip-limit 10)
Which means that, if you already have R and ESS in your Emacs, you can install company, add this lines to your init file and it should work the same as it works for me. To this I can only add that there are more auto-completions tools for emacs that you can install and configure to your liking, but since ESS uses Company by default and I like how it works, I keep it for myself.
To this I want to add that, I don't know all the possibilities of RStudio, but I can tell you that with emacs you have a lot of other packages and tools that are super useful for coding, and lately also many for data analysis. Some of my favs is the (show-paren-mode 1)
that highlights which parenthesis is matched when opening or closing (see image below), and the package rainbow-delimiters that let you choose a color for different level of parenthesis, making it easy to navigate. Here is a screen shot of both
I'm planning to make some posts on these and other packages useful for R and Data Analysis in Emacs along this year.
As for Rmd and quarto, both are markdown and both can be rendered to HTML and other formats with their respective R libraries so, I simply have them installed and call them when I need them. Emacs can visualize both well with its own markdown-mode, but the library polymode helps with visualization, movement, editing, etc., you just need to install poly-r as well. And there is also quarto-mode which I haven't try yet but you can be sure I will in the near future. I just got started with Quarto recently so I can't say much about it yet, but I use Rmd
files for my work and my Master's homework with no complains. And by the way, speaking of writing documents, there is also wonderful package called yasnippet that lets you work with templates in emacs, I use it for both, my R files and my Rmd docs as well. It's super useful, in short, you create a template you want, you save it with a keyword and then you just type the keyword and at the end press TAB
and it will expand to the full template. Is really useful to use, check the link.
My problem with ESS is the fact that you won't be able to get Company to provide completions for column names inside functions, so if you consider this example:
library(data.table)
cars_df = as.data.table(mtcars)
cars_df[, mean(cyl)]
When using ESS, it won't provide suggestions for column names when typing inside mean()
. It's a long-standing issue with ESS itself, and it seems like nobody has a will or interest to address it.
On the other hand, there are some nice things about using Emacs for R development. Magit is a fantastic git client and Projectile makes it easy to navigate through your project and jumping between projects. I think you should look into what other Emacs frameworks like Doom Emacs and Spacemacs have to offer in terms of R setup. There can many packages that help with programming, which are sometimes difficult to find on your own.
Using Emacs for R | R with White Dwarf
Emacs is an easy to use text editor that, combined with ESS can make a powerful IDE for working with R
https://blog.rwhitedwarf.com/post/use_emacs_for_r/