Making R Files Executable (under Windows)
来源:互联网 发布:布谷鸟网络电视回看 编辑:程序博客网 时间:2024/06/18 01:31
Although it is reasonable that R scripts get opened in edit mode by default, it would be even nicer (once in a while) to run them with a simple double-click. Well, here we go ...
Choosing a new file extension name (.Rexec)
First, we have to think about a new file extension name. While double-click to run is a nice-to-have, the default behaviour should not be overwritten. In the Windows universe one cannot simply attach two different behaviours to the same file extension but we can register new extensions and associate custom defaults to those. Therefore we need another, new file extension.
To make the file extension as self-explanatory as possible, I suggest using .Rexec for R scripts that should be executable while leaving the default system behaviour for.R files as is.
Associating a new file type with the .Rexec extension
In the next step, we tell Windows that the .Rexec file extension is associated with theRScriptExecutable file type. Furthermore, we inform Windows how these kind of files should be opened by default.
To do so, we need access to the command line interface, e.g., via cmd. ClickStart and type cmd into the search bar. Instead of hitting enter right away, right click on the'cmd.exe' search result, choose Run as administrator from the context menu, and clickYes on the following pop up window. The windows command line should pop up thereafter.
Within the command line, type first:
ASSOC .Rexec=RScriptExecutable
... then ... FTYPE RScriptExecutable=C:Program FilesRR-3.1.2binx64Rscript.exe %1 %*
... while making sure that the path used above really leads to your most recent/preferredRScript.exe.
Testing
To test if everything works as expected, create an R script and write the following lines:
message(getwd())for(i in 1:100) { cat(".") Sys.sleep(0.01)}message("nBye.")Sys.sleep(3)
Save it as, e.g., 'test.Rexec' and double click on the file. Now a black box should pop up, informing you about the current working directory, and printing 100 dots on the screen and terminate itself after saying'Bye'.
Et voilà.
One more thing (or two)
While you are now able to produce executable R script files, note that it is also very easy to transform those back by simply changing the file extension from.Rexec to .R and vice versa.
If you execute your R scripts from the command line, you might want to save yourself from having to add the file extension every time. Simply register.Rexec as a file extension that is executable. The PATHEXT environment variable stores all executable file types. Either go to:Start > Control Panel > System > Advanced System Settings > Environment Variables and search for the'PATHEXT' entry under System Variables and add .Rexec to the end of the line like that: '.COM;.EXE;.BAT;.Rexec', or go to the command line again and type:
set PATHEXT=%PATHEXT%;.Rexec
Sources of knowledge
- FTYPE documentation
- ASSOC documentation
- Making R Files Executable (under Windows)
- Making SQLITE/SQLITE3 executable scripts
- Calling Executable Files in PowerShell
- How Linux creates device files under /dev
- GSL under Windows[转]
- Compiling Graphite under Windows
- GSL under Windows[转]
- Making your windows folder smaller
- Making Nameless Folder In Windows
- intall R 12.0 under centos 5.5
- Tramp Emacs & plink under windows
- Mastering XML under Windows CE
- executing AT-commands under Windows
- Android: Run systrace under windows
- Power Management under Windows CE
- Making plain binary files using a C compiler(ZT)
- Making plain binary files using a C compiler (i386+)
- Making plain binary files using a C compiler (i386+)
- hdu 2222 ac自动机
- A1006 SignIn and SignOut
- UltraEdit编译C语言程序并运行的示例
- ES学习笔记四-Query DSL
- Android获得全局进程信息以及进程使用的内存情况
- Making R Files Executable (under Windows)
- 【计算机组成与设计学习笔记】(二)
- 2015-02-14 开讲啦 周华健:有没有一首歌会让你想起自己
- 轻松搭建hadoop-1.2.1集群(3)--配置hadoop集群软件
- 【BZOJ 1055】 [HAOI2008]玩具取名
- Remove Duplicates from Sorted Array - LeetCode
- POJ 3253 Fence Repair——优先队列 用long long或__int64才能过
- centos 7 挂载NTFS硬盘
- RTutor Kicks Off: An Interactive R Problem Set about Top Income Taxation