0

I'm trying to create a bat file that will do a web search of a company ticker and then email the .txt file output. I'm currently using this line in the .bat file:

@echo off  R CMD BATCH \\PERFILE01\PER1_MyDocs3\W47382\Desktop\R_Automation\WebCorpus_run.R

When I run the file, the following error appears: 'R' is not recognized as an internal or external command, operable program or batch file.

I realize there are many others with the same issue, however I am still yet to resolve mine.

Rohan Khude
  • 4,455
  • 5
  • 49
  • 47
Harry
  • 3
  • 1
  • 4
  • 1
    Make sure R is in your path. – Hong Ooi Nov 22 '16 at 05:39
  • sorry, i have seen this many times, but I'm not sure how to do this. – Harry Nov 22 '16 at 05:40
  • I have found another website which explains the R path I think - by going into the computer's advanced security setting. I need administrator password however as I am on a work computer, so I will need to obtain that first. – Harry Nov 22 '16 at 05:53
  • Not 100%... You can set the path variable as well during the run of your batch file. This will be temporary but should work... Have a look at my answer :) – geisterfurz007 Nov 22 '16 at 06:23
  • @Harry The simple solution for error message `is not recognized as an internal or external command` is specifying the application or script to run with full path and with file extension enclosed in double quotes instead of only specifying it with file name only. Then Windows command interpreter does not need to search for `R.*` with a file extension listed in environment variable `PATHEXT` in current directory or all directories of __local__ `PATH` being a combination of __system__ `PATH` and __user__ `PATH` perhaps even modified in local or parent process. – Mofi Nov 22 '16 at 06:25

1 Answers1

-1

Based on where R is installed/placed do the following:

@echo off
set "your_path=C:\PathTo\R"
set PATH=%PATH%;%your_path%
set PATH

This should set the PATH variable to include the value of your_path for the duration of your batch file.
Notice that when you run the batch file it will include your_path; when you start another command line window and type set PATH then your_path will not appear.
So this is only temporary and not for all users.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
  • yep thanks everyone, i copied the instructions on this website: https://stevemosher.wordpress.com/step-two-get-to-know-your-windows-system/ which helped fix that problem – Harry Nov 23 '16 at 05:35