You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support stdin and stdout as input file and output file in command line? #494
Thanks for clarifying. I think an alternative would be the following:
Put an executable R script with shebang in a place that is part of your PATH or in a new directory and add that directory to your path. I am on Mac, so I put export PATH = $PATH:~/custom_bin in .bash_profile and then put the following script callerd styler.r in the custom_bin directory:
#!/usr/local/bin/Rscriptcon<- file("stdin")
out<-styler::style_text(readLines(con))
close(con)
out
Make the file executable with chmod +x ~/custom_bin/styler.r
Now you can conveniently call it similar to a littler script.
For vim plugin support, the formatter tool should be a single excutable or a one liner code.
Packing styler into script not a good solution, cause you need to generate the script manually when you start a new environment.
For vim plugin support, the formatter tool should be a single excutable or a one liner code.
Packing styler into script not a good solution, cause you need to generate the script manually when you start a new environment.
Ok. So we have support for styler in ale, just added a few days ago, which is a VIM Plug-in: dense-analysis/ale#2401 (comment). Maybe this is what you are looking for?
I also pushed a commit for styler support in neoformat (another popular vim plugin) a few days ago, but it is not perfect. I need readr for styler to make it work.
BTW, the performance of styler is a little slow. Even if the file is well formatted.
styler::style_text (for 20 lines of R code)
cat test.R 0.00s user 0.00s system 79% cpu 0.001 total
R --slave --no-restore --no-save -e 0.40s user 0.02s system 100% cpu 0.411 total
black formatter of python (for a large file)
> time black -l 79 test.py
reformatted test.py
All done! ✨ 🍰 ✨
1 file reformatted.
black -l 79 test.py 0.14s user 0.02s system 38% cpu 0.406 total
> time black -l 79 test.py
All done! ✨ 🍰 ✨
1 file left unchanged.
black -l 79 test.py 0.07s user 0.01s system 99% cpu 0.082 total
Activity
lorenzwalthert commentedon Apr 24, 2019
Thanks for clarifying. I think an alternative would be the following:
export PATH = $PATH:~/custom_binin.bash_profileand then put the following script callerdstyler.rin thecustom_bindirectory:chmod +x ~/custom_bin/styler.ror
cat r-script.R | styler.rif your code is in a script.
y9c commentedon Apr 24, 2019
How about adding stdin argument into styler.
It is possible to do that in formatR.
y9c commentedon Apr 24, 2019
For vim plugin support, the formatter tool should be a single excutable or a one liner code.
Packing styler into script not a good solution, cause you need to generate the script manually when you start a new environment.
lorenzwalthert commentedon Apr 24, 2019
Ok. So we have support for styler in ale, just added a few days ago, which is a VIM Plug-in: dense-analysis/ale#2401 (comment). Maybe this is what you are looking for?
y9c commentedon Apr 24, 2019
I also pushed a commit for styler support in neoformat (another popular vim plugin) a few days ago, but it is not perfect. I need readr for styler to make it work.
https://github.com/sbdchd/neoformat/blob/924dee18e7ca547e105ab8d800069fc5829b019b/autoload/neoformat/formatters/r.vim#L8
lorenzwalthert commentedon Apr 24, 2019
But why not using the approach I used above with readLines(file(„stdin“)) instead of the approach with readr?
y9c commentedon May 2, 2019
I forget to close file, and got some error in the first attempt.
It works fine now. Thank you @lorenzwalthert
BTW, the performance of styler is a little slow. Even if the file is well formatted.
styler::style_text (for 20 lines of R code)
black formatter of python (for a large file)