7

I often find it more useful to run R on the command line (windows). However when I try it in Powershell I tend to run into problems, but this is easily overcome by first running cmd and then it works.

This is the error I get when I do R CMD BATCH

Invoke-History: A positional parameter cannot be found that accepts the argument 'BATCH'

I later realised that r is an alias that returns the immediate past command, hence my inability to run R.

Subsequently, I found that using the full filename for the executable (i.e. R.exe) or using Rcmd.exe (i.e. Rcmd BATCH ...) worked.

However, I'm just curious, is there a work around, in case one runs into similar conflicts?

3
  • Do you want to run an R session in terminal or run R scripts at command line? Commented Aug 27, 2017 at 14:01
  • My intention is to run R CMD with its options like build, INSTALL, check, etc. Commented Aug 27, 2017 at 14:18
  • 1
    I think you found the workaround: use the full filename, including the extension Commented Aug 27, 2017 at 14:32

3 Answers 3

10

To start R in powershell:

R.exe
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I've since learned to use R in PowerShell or cmd.exe by running rterm.
If you need to enter R.exe in your system %PATH%, just restarting the installer will remind you where the binary is. Note that just typing R invokes PowerShell's history feature, which masks the executable.
2

The workaround would be fully defining your calls.

& "path\to the\r.exe" arg1 arg2 etc

Alternatively,

$P = @{
  FilePath="path\to the\r.exe"
  ArgumentList=@('arg1','arg2')
}
Start-Process @P

6 Comments

Thanks. One of the reasons I asked this question is due to an unrelated issue wherein I cannot run 7-Zip's 7z in PS 2.0, while it works perfectly when I run it in cmd. So I am unable to use a script containing it.
Do you get errors? I haven't run into any issues with the 7z cli in ps2 scripts
It's on my workplace machine. When I get there tomorrow, I will post the error for all to see. Thanks, again.
I am aware that PS 2.0 is being deprecated, but I think it may be worth pointing out, even if it's for academic interest.
@VictorOrdu I'm also stuck on v2 in my workplace for the time being.
|
1

I ran into this problem on linux, where there is no file extension for executables, so that didn't help, but still there are two options:

  • /usr/bin/R if it is installed in the usual location
  • Start-Process R (the start-process cmdlet does not need to be capitalized)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.