Skip to content
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

lintr not working until linter_cache created #2

Open
aezarebski opened this issue Jan 26, 2021 · 8 comments
Open

lintr not working until linter_cache created #2

aezarebski opened this issue Jan 26, 2021 · 8 comments

Comments

@aezarebski
Copy link

I couldn't get lintr to work until I found the linked SO post which explains you need a ~/.R/lintr_cache to exist before you can actually see any errors. Potentially useful to point this out.

https://emacs.stackexchange.com/a/57800

@frederic-santos
Copy link
Member

frederic-santos commented Jan 27, 2021

This is quite strange, I don't remember such an issue on my computer. I'm pretty sure I didn't have to do that. (But actually, I had other weird issues when setting up lintr. They were related to the system package icu on my ArchLinux system, which was far from an easy guess, but fortunately easy to solve.)
I can definitely point out this problem, however. Thanks! ;)

@aezarebski
Copy link
Author

I'm not sure if there is already this functionality built into lintr, but a related hack I use is the following function which uses the styler package to pretty-print all the code in a buffer. Thought I'd add it here in case you are interested.

(defun styler-reformat-buffer ()
  "Run styler::style_file on the current buffer and then revert to load any changes."
  (interactive "*")
  (shell-command (concat "Rscript --slave --no-restore --quiet --no-init-file -e \"styler::style_file('" (buffer-file-name)  "')\""))
  (revert-buffer nil t)
)

@frederic-santos
Copy link
Member

Great trick, thanks!
Actually someone asked for such a feature in our "Topic" wiki (17. Auto-formatting code: does this already exist in ESS?). I don't think this topic deserves a full repo on its own, but this might be a trick you'll want to show in a short video (for example for topics 15 or 16?). As you wish! ;)

@aezarebski
Copy link
Author

Yer, that was me, I was hoping someone would be able to point out a better way to do it. Dirk referenced some stuff material, but I didn't understand to use it to pretty print a whole file. Definitely not worth a repo/presentation.

@eddelbuettel
Copy link
Member

Mark a region via C-SPACE and movement, then C-M \ reindents. Works for every programming mode ❤️

@aezarebski
Copy link
Author

Aha! Of course emacs has an indentation program dating back to 1985. Thanks for the clarification on the usage :)

The styler::style_file function addresses more of the stuff flagged by lintr (i.e., spacing around , and <-), but language agnostic indentation is a nifty tool.

@eddelbuettel
Copy link
Member

(Strictly personally speaking) I find the lintr way too invasive; at some point ESS default to using it as soon as it saw it installed. That got fixed. Ditto with the style. I have been reading R (and S) code for a long time and prefer the existing style.

Which Emacs supports. It's even in the 'R internals' manual and has been since approximately forever.

@eddelbuettel
Copy link
Member

Aha! Of course emacs has an indentation program dating back to 1985. Thanks for the clarification on the usage :)

BTW I also mentioned that in my (very initial, still very short) 'basic editing' contribution (draft) Rmd pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants