Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call an executable from R script

Tags:

r

I have a CUDA code which I have compiled and have the executable of it. Now I want to call this executable from a R script and pass it arguments also from the R script itself? Is it possible? If yes, please explain how?

like image 431
user1439690 Avatar asked May 07 '26 10:05

user1439690


2 Answers

To call any external executables you can use the system function:

system("cuda_exe arg1 arg2")

where cuda_exe is the cuda executable, and arg* are the command line arguments passed to the script.

like image 166
Paul Hiemstra Avatar answered May 09 '26 23:05

Paul Hiemstra


A more cross-platform alternative than system is system2. It'll work on Windows and other systems without a /bin/sh.

system2("cuda_exe", c("arg1", "arg2"))

It requires no shell, but shell syntax like the * glob won't work, and you'll have to learn the R way of doing things, such as list.files(pattern = ".*.csv") instead of just "*.csv". The upside is that you won't have to fiddle with paste() to construct the command line.

like image 33
meedstrom Avatar answered May 09 '26 23:05

meedstrom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!