I have used R in the past to do very basic calls to the commmand line. The example can be found here.
This time around, I am looking to mimic this code which runs successfully from the command line in Windows:
> cd C:\Documents and Settings\BTIBERT\My Documents\My Dropbox\Eclipse\Projects\R\MLB\retrosheet\rawdata > bgame -y 2010 2010bos.eva >2010bos.txt
This is the code I am trying to run inside of R. I have already set the working directory inside of R.
dir <- paste("cd", getwd(), sep=" ") system(dir) system("bgame -y 2010 2010bos.eva >2010bos.txt")
I am sure this is user error, but what am I doing wrong? It appears to work initially, but returns the following error. I very well could be doing something wrong, but I believe I am using the same commands.
Expanded game descriptor, version 109(185) of 05/08/2008. Type 'bgame -h' for help. Copyright (c) 2001 by DiamondWare. [Processing file 2010bos.eva.] >2010bos.txt: can't open. Warning message: running command 'bgame -y 2010 2010bos.eva >2010bos.txt' had status 2
Any help you can provide will be appreciated.
A system call is a programmatic way a program requests a service from the kernel, and strace is a powerful tool that allows you to trace the thin layer between user processes and the Linux kernel. To understand how an operating system works, you first need to understand how system calls work.
R CMD check runs all sorts of checks on the contents of an R package, and gives warnings and error messages when it finds things that aren't right. It also will run the examples in the . Rd files for each of your functions, as well as other automated tests that you've included.
To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.
fopen is a function call, but it may sometimes be referred to as a system call because it is ultimately handled by the "system" (the OS). fopen is built into the C runtime library.
You need to issue all commands in one system()
call:
system(paste("cd",getwd() "&& bgame -y 2010 2010bos.eva >2010bos.txt",sep=" "))
You should already be in your working directory, so I'm not sure the cd getwd()
is necessary. And you may need quotes around your path because it contains spaces. The error may be resolved by putting spaces around >
.
If I were in your shoes, I would try this:
system("bgame -y 2010 2010bos.eva > 2010bos.txt")
UPDATE:
And you should probably heed this advice in the "Differences between Unix and Windows" section of ?system
that says you should use shell
:
• The most important difference is that on a Unix-alike ‘system’ launches a shell which then runs ‘command’. On Windows the command is run directly - use ‘shell’ for an interface which runs ‘command’ _via_ a shell (by default the Windows shell ‘cmd.exe’, which has many differences from the POSIX shell). This means that it cannot be assumed that redirection or piping will work in ‘system’ (redirection sometimes does, but we have seen cases where it stopped working after a Windows security patch), and ‘system2’ (or ‘shell’) must be used on Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With