tags:

views:

220

answers:

4

Is there any usable emacs mode for Rscript?

(Rscript is the script front-end for the R language.)

If I type this:

#!/usr/bin/Rscript
print(commandArgs(TRUE))

and do indent in the ESS R-mode it indents the first line like crazy, since it sees it as a comment:

                          #!/usr/bin/Rscript
print(commandArgs(TRUE))
A: 

Try shell-script-mode - with some notes on customized indentation

It indented your code just fine, for me.

Michael Paulukonis
Any reason for the drive-by down-vote? As I said, what I linked to corrected the bad indentation the OP complained about; if this is not helpful, please ignore. If wrong or harmful, downvote -- but do everybody the courtesy of explaining WHY it is wrong.
Michael Paulukonis
+1  A: 

There isn't, but you can force your Rscript into R editing mode by making the second line of the file look like this:

# -*- mode: R -*-

(More information here.)

David Smith
Also, if you end them .R (my choice for normal R files) or .r (my choice for littler or Rscript 'scripts') the mode tends get assigned automatically to.
Dirk Eddelbuettel
+1  A: 

As of version 5.9, ESS will recognize scripts using the Rscript or litter interpreter; see http://ess.r-project.org/Manual/ess.html#New-features.

For reference, to assign a mode to an interpreter, use the interpreter-mode-alist variable. For example,

(add-to-list 'interpreter-mode-alist '("Rscript" . r-mode))

Any file with a first line like "#!/usr/bin/Rscript" will be recognized as r-mode.

jrnold