root <- tempdir()
# ------ Case 1: basic use case -------
# Create a path in root
dir_create2(file.path(root, 'a'))
# find path even it's missing. The search path will be
# root/ins/cd/a - missing
# root/cd/a - missing
# root/a - exists!
find_path('ins/cd/a', root)
# ------ Case 2: priority -------
# Create two paths in root
dir_create2(file.path(root, 'cc/a'))
dir_create2(file.path(root, 'a'))
# If two paths exist, return the first path found
# root/ins/cd/a - missing
# root/cd/a - exists - returned
# root/a - exists, but ignored
find_path('ins/cc/a', root)
# ------ Case 3: find all -------
# Create two paths in root
dir_create2(file.path(root, 'cc/a'))
dir_create2(file.path(root, 'a'))
# If two paths exist, return the first path found
# root/ins/cd/a - missing
# root/cd/a - exists - returned
# root/a - exists - returned
find_path('ins/cc/a', root, all = TRUE)
Run the code above in your browser using DataLab