This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Run Windows CMD commands from R

Hello,

I need to design a function in R that can direct the windows CMD to run a command. The command is:

"copy *.txt combinedfiles.txt"

I used this command

system("cmd.exe copy *.txt combinedfiles.txt")

I am a beginner at R-Studio. So, if this question sounds childish to you please pardon me.

Kindly help me out. Thanks

r genome

2 answers

Why use a non-portable solution, if R provides you with a portable one:

file.copy( from, to, overwrite = recursive, recursive = FALSE, copy.mode = TRUE, copy.date = FALSE )

For Windows try using shell:

shell("copy test1.txt test1_mycopy.txt")

But I agree with @h.mon, and would prefer to use file.copy.

Log in to answer this question.