wait_copy: wait copy

Description Usage Arguments Details Value Examples

View source: R/copy_files.R

Description

Copy files from one location to another, during set hours if desired. This is very useful for copying from networked drives that get a lot of activity during the day.

Usage

1
2
3
4
5
wait_copy(file_list, to_dir = ".", json_meta = "all_meta_data.json",
  tmp_loc = "/tmp", clean_file_fun = clean_filename, time_limit = TRUE,
  start_time = hours(20), stop_time = hours(30), time_zone = NULL,
  wait_check = 1800, n_check = Inf, wait_files = 10, pause_wait = 10,
  pause_file = 2)

Arguments

file_list

a character vector of files to copy from

to_dir

where to copy the files to

json_meta

the json meta flat file

tmp_loc

a temp file location

clean_file_fun

function to use for cleaning up the file name?

time_limit

only copy during a certain time?

start_time

when to start copying

stop_time

when to stop copying

time_zone

what time zone are we in

wait_check

how long to wait before checking again

n_check

how many times to try before giving up

wait_files

how many files before pausing

pause_wait

how long to pause when the wait limit is reached

pause_file

how long to pause between every file

Details

  1. Limiting by time of day: if time_limit = TRUE, the start_time and stop_time are assumed to be on a per day basis, so they should be encoded as the number of hours from midnight. The function actually does a periodic check as to whether the start_time is ahead of it, and if it is not, then it will create a new time interval for the copying to be allowed. Default is from 8pm (20:00) to 6am (30:00). The wait_check parameter sets how often to wait before checking the time again (default is 1800 seconds / 30 minutes), and n_check parameter defines how many times to check if the copying can be done (defaults to infinite).

  2. Time Zone: Provide your time zone so that the time functionality works properly!

  3. Waiting Between Copies: In addition to only copying between certain hours, it is possible to set how long to pause between each file using pause_file, default is 2 seconds, and also a longer interval after copying several files using wait_files (10 files) and pause_wait (10 seconds).

  4. Checking for files: It is recommended before running wait_copy to first run check_files_exist on the file list to copy to make sure that you are passing valid file paths.

Value

logical

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 

  # assume files are in /home/tmp/
  # assume current working directory is where to copy to
  file_list <- dir(".", full.names = TRUE)
  wait_copy(file_list) # copy between 8pm and 6am

  # no time limit for copying
  wait_copy(file_list, time_limit = FALSE)

  # copy from 10am to 1pm (13:00)
  wait_copy(file_list, start_time = hours(10), stop_time = hours(13))

  # stop checking if can copy after particular number of checks (3)
  wait_copy(file_list, n_check = 3)

  # check every 30 seconds instead of 30 minutes
  wait_copy(file_list, wait_check = 30)

  # pause 4 seconds between each file
  wait_copy(file_list, pause_file = 4)

  # pause 30 seconds after every 20 files
  wait_copy(file_list, wait_files = 20, pause_wait = 30)

  # don't rename the files
  wait_copy(file_list, clean_file_fun = NULL)

  # use make.names instead
  wait_copy(file_list, clean_file_fun = make.names)


## End(Not run)

rmflight/waitcopy documentation built on May 24, 2019, 6:18 a.m.