3

I am trying to copy and paste a 1.5G file from local folder A to shared drive folder B and another local folder C. file.copy is too slow, takes about 5-10 mins. Are there any other recommendations to improve the performance?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
C_Mu
  • 305
  • 4
  • 14
  • 2
    I imagine this has close to nothing to do with R or its `file.copy` function, which should just be calling a system function for copying. – thelatemail Aug 16 '18 at 22:19
  • 1
    Agree with @thelatemail that this probably a question about the underlying OS/system copying process. May be better for https://superuser.com ... Can you say more about what OS you're on, where (physically) the shared drive is [e.g. what kind of network connection], etc. ? . Googling "slow copy to shared drive" brings up a lot of stuff about Windows copying. – Ben Bolker Aug 16 '18 at 22:38
  • when I manually ctrl c and ctrl v, it is ok, but using R to copy and paste, it is significantly lower than manual work. thats why I am guessing it is due to the file.copy function – C_Mu Aug 16 '18 at 23:05
  • 1
    My apologies, I just assumed with R's `file.copy` calling an `.Internal` function that it would be a standard system call. Clearly, I got ahead of myself! – thelatemail Aug 16 '18 at 23:40
  • can you say more about your OS? something like @user26055553's answer should work, but a variation would be needed on Windows (and *might* different by OS version?) – Ben Bolker Aug 16 '18 at 23:43
  • mine is window 10 pro, i try @user26055553's answer, nothing happened after the code, no error shows too – C_Mu Aug 17 '18 at 15:02

2 Answers2

2

I am not sure why (if?) this is happening but you can always use your operating system's native commands. E.g., assuming that you are using macOS or Linux:

system(sprintf('cp %s %s', source, target))

where source and target are your file paths.

user2605553
  • 362
  • 1
  • 2
  • 9
  • this is worth a try. Almost certainly will show the OP that the underlying OS copy operation is the problem, not `file.copy()`. – Ben Bolker Aug 16 '18 at 22:36
  • 1
    I'm not sure. It appears that R has it's own copy and at least in some instances it struggles with caching etc. For example: https://stackoverflow.com/questions/49888078/r-copying-files-over-network-much-slower-with-file-copy-than-systemmv – user2605553 Aug 16 '18 at 22:42
  • 1
    OK, you learn something every day! Maybe link that question in your answer? (Still would be helpful to know more about the OP's system) – Ben Bolker Aug 16 '18 at 22:48
  • @BenBolker - well, I feel like a dill now! :-D – thelatemail Aug 16 '18 at 23:37
  • Thanks for your post, I try your code, it is not working, no error shows up, but the file is not moved also, like nothing happened. here is my code: system(sprintf('cp %s %s', "C:/Users/myname/Documents/filename.accdb", "W:/path/Archive/filename.accdb")). Any suggestion? – C_Mu Aug 17 '18 at 15:04
  • The example I gave you works in macOS/Linux. Looks like you are on Windows. You will have to replace the command inside sprintf with a Windows command: https://www.computerhope.com/copyhlp.htm – user2605553 Aug 17 '18 at 15:35
0

If you are on windows use powershell:

comm.cp <- paste0("powershell -command Copy-Item ",source," ", target, " -Force"  );
copied <- system(comm.cp, wait = TRUE);
dez
  • 1
  • 1