-1

I have a vector of filenames A and I have an equivalent vector of new names for those files -- B.

I was hoping to do:

test <-map2(A, B, ~system2('mv', args=c(.x, .y)))

or perhaps

test <-map2(A, B, ~system2('mv', args=paste(.x, .y)))

but .x and .y don't get interpreted nicely and the command fails.

mv: cannot stat '/home/rob/KRBD_Data/Client_ID/000/raw/monthzips/2015-01/Data_2015-01-07.zip'

If I use rename as the command I get

test <-map2(A, B, ~system2('rename', args=paste(.x, .y)))

Unknown regexp modifier "/r" at (user-supplied code), at end of line

Unknown regexp modifier "/b" at (user-supplied code), at end of line

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
user2292410
  • 447
  • 4
  • 13

1 Answers1

0

If you paste together the arguments, the system2 function will escape that space that separates them, as though it's one long filename that contains a space.

Instead, pass both the arguments as a vector:

test <-map2(A, B, ~system2('mv', args=c(.x, .y)))
David Robinson
  • 77,383
  • 16
  • 167
  • 187
  • That worked. In fact I was distracted by one missing file, it had been working for a few iterations. Dah! Thank you! – user2292410 May 17 '17 at 21:52