The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Title: Facilitate File Handling, Directory Comparison & Synchronization
Version: 0.1.1
Description: Compare directories flexibly (by date, content, or both) and synchronize files efficiently, with asymmetric and symmetric modes, helper tools, and visualization support for file management.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Imports: collapse, data.table, digest, secretbase, cli, DT, fs, joyn (≥ 0.3.0), stats, knitr, utils, rstudioapi
Suggests: fst, withr, rmarkdown, mockery, testthat (≥ 3.0.0)
Depends: R (≥ 4.1.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
URL: https://rossanatat.github.io/syncdr/, https://github.com/RossanaTat/syncdr
BugReports: https://github.com/RossanaTat/syncdr/issues
NeedsCompilation: no
Packaged: 2026-01-23 21:57:30 UTC; wb621604
Author: R.Andres Castaneda [aut], Rossana Tatulli [aut, cre], Global Poverty and Inequality Data Team World Bank [cph]
Maintainer: Rossana Tatulli <rtatulli@worldbank.org>
Repository: CRAN
Date/Publication: 2026-01-27 21:30:02 UTC

syncdr: Facilitate File Handling, Directory Comparison & Synchronization

Description

Compare directories flexibly (by date, content, or both) and synchronize files efficiently, with asymmetric and symmetric modes, helper tools, and visualization support for file management.

Author(s)

Maintainer: Rossana Tatulli rtatulli@worldbank.org

Authors:

Other contributors:

See Also

Useful links:


Partial asymmetric synchronization to right (update common files)

Description

Partially synchronize right directory based on left one -i.e., the function will:

Usage

common_files_asym_sync_to_right(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  by_date = TRUE,
  by_content = FALSE,
  recurse = TRUE,
  force = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

by_date

logical, TRUE by default

by_content

logical, FALSE by default

recurse

logical, TRUE by default. If recurse is TRUE: when copying a file from source folder to destination folder, the file will be copied into the corresponding (sub)directory. If the sub(directory) where the file is located does not exist in destination folder (or you are not sure), set recurse to FALSE, and the file will be copied at the top level

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, Displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Value

Invisible TRUE indicating successful synchronization.

Examples

# Asymmetric synchronization of common files


e <- toy_dirs()
left  <- e$left
right <- e$right
# Synchronize common files by content only
common_files_asym_sync_to_right(
  left_path  = left,
  right_path = right,
  by_date    = FALSE,
  by_content = TRUE
)


Compare Two Directories for Synchronization Status

Description

This function compares two directories, typically referred to as 'left' and 'right', to determine their synchronization status at the file level. The primary goal is to identify the synchronization status of files present in both directories and those exclusive to either directory.

Usage

compare_directories(
  left_path,
  right_path,
  recurse = TRUE,
  by_date = TRUE,
  by_content = FALSE,
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

recurse

If TRUE, fully recurses through subdirectories. If a positive integer, specifies the number of levels to recurse.

by_date

Logical. If TRUE (default), compares directories based on the modification date of common files.

by_content

Logical. If TRUE, compares directories based on the hashed content of common files. Default is FALSE

verbose

Logical. If TRUE display additional info on the comparison process. Default is FALSE

Value

A list of class "syncdr_status" containing the following elements:

Sync Status Types

The synchronization status is determined for files present in both directories, as well as for files exclusive to either directory. It can be computed based on modification date only, content only, or both.

For Common Files:

For Non-Common Files:

Examples


e <- toy_dirs()
left  <- e$left
right <- e$right
compare_directories(left, right)
compare_directories(left, right, by_content = TRUE)
compare_directories(left, right, by_content = TRUE, by_date = FALSE)


Compare contents of two files and determine synchronization status

Description

This function compares the contents of two files located at specified paths and determines their synchronization status based on their content

Usage

compare_file_contents(
  path_left,
  path_right,
  verbose = getOption("syncdr.verbose")
)

Arguments

path_left

A character string specifying the path to the file in the left directory.

path_right

A character string specifying the path to the file in the right directory.

verbose

logical; if TRUE display progress status of hashing files' contents, in seconds. Default is FALSE

Value

A list containing the following components:

is_diff

Logical. Indicates whether the contents of the two files are different (TRUE) or identical (FALSE).

sync_status_content

Character. Describes the synchronization status between the two files based on their content: - "different content": Contents of the files are not identical. - "same content": Contents of the files are identical.


Compare modification times of two files and determine synchronization status

Description

This function compares the date of last modification of two files and determines their synchronization status

Usage

compare_modification_times(modification_time_left, modification_time_right)

Arguments

modification_time_left

modification time of the file in the left directory

modification_time_right

modification time of the file in the right directory

Value

A list containing the following components:

is_new_left

Logical. Indicates if the file in the left directory is newer (i.e., has a later modification time) than the file in the right directory

is_new_right

Logical. Indicates if the file in the right directory is newer (i.e., has a later modification time) than the file in the left directory

sync_status_date

Character. Describes the synchronization status between the two files based on their modification times: - "newer in left, older in right dir": Left file is newer than right file. - "older in left, newer in right dir": Right file is newer than left file. - "same date": Both files have the same modification time.


Copy files from right directory to left directory

Description

This function copies files from a right (source) directory to a left (destination) directory based on a provided data frame containing file paths and synchronization status.

Usage

copy_files_to_left(left_dir, right_dir, files_to_copy, recurse = TRUE)

Arguments

left_dir

Path of the left (destination) directory.

right_dir

Path of the right (source) directory.

files_to_copy

Data frame containing paths of files to copy and their synchronization status.

recurse

Logical, default is TRUE.

  • If TRUE: Files are copied into corresponding subdirectories in the left directory. If a subdirectory doesn't exist in the left directory, it will be created.

  • If FALSE: Files are copied to the top level of the left directory.

Details

The function performs the following steps:

  1. Checks if the source (right) and destination (left) directories exist and creates the destination directory if it doesn't already exist.

  2. Copies files from the right directory to the corresponding subdirectory in the left directory based on the provided file paths.

Value

Invisible TRUE upon successful completion of the file copying process.


Copy files from left to right directory

Description

This function copies files from a source directory (left_dir) to a destination directory (right_dir) based on a provided data frame containing file paths and synchronization status.

Usage

copy_files_to_right(left_dir, right_dir, files_to_copy, recurse = TRUE)

Arguments

left_dir

Path of the source directory (left/leader).

right_dir

Path of the destination directory (right/follower).

files_to_copy

Data frame containing paths of files to copy and their synchronization status.

recurse

Logical, default is TRUE.

  • If TRUE: Files are copied into corresponding sub-directories in the destination folder. If a subdirectory doesn't exist in the destination, it will be created.

  • If FALSE: Files are copied to the top level of the destination directory.

Details

The function performs the following steps:

  1. Checks if the source and destination directories exist and creates the destination directory if it doesn't already exist.

  2. Copies files from the source directory to the corresponding subdirectory in the destination directory based on the provided file paths.

Value

Invisible TRUE upon successful completion of the file copying process.


Create a temporary copy of .syncdrenv to test functions

Description

This function creates a copy of the original environment, allowing tests to be executed without modifying the original environment.

Usage

copy_temp_environment()

Value

A list of temporary paths left and right.


Retrieve information about files in a directory

Description

This function retrieves information about files in a specified directory

Usage

directory_info(dir, recurse = TRUE)

Arguments

dir

A character string representing the path of the directory.

recurse

Logical. If TRUE, fully recurse into subdirectories. If a positive number, specifies the number of levels to recurse.

Value

A data frame containing detailed information about the files in the directory, including all information produced by fs::file_info().


Display tree structure of one (or two) directory

Description

Display tree structure of one (or two) directory

Usage

display_dir_tree(path_left = NULL, path_right = NULL, recurse = TRUE)

Arguments

path_left

path of left directory

path_right

path of right directory

recurse

logical, default to TRUE: show also sub-directories

Value

directories tree

Examples

# Create a temporary directory structure


e <- toy_dirs()
left  <- e$left
right <- e$right

display_dir_tree(
  path_left  = left,
  path_right = right
)

display_dir_tree(path_right = right)


Display file actions in table

Description

This function displays actions (either "copy" or "delete") to be performed on a list of files.

Usage

display_file_actions(path_to_files, directory, action = c("copy", "delete"))

Arguments

path_to_files

Data frame containing the paths to the files. The data frame should have a column named "Paths".

directory

Character string specifying path to directory where action is taken

action

Character vector specifying the action to be performed on the files. Options are "copy" (default) or "delete".

Value

console-friendly table with files and actions


Display status of synchronization/comparison info between two directories in DT table

Description

Display status of synchronization/comparison info between two directories in DT table

Usage

display_sync_status(sync_status_files, left_path, right_path)

Arguments

sync_status_files

object of compare_directories() output, either common_files or non_common_files

left_path

A character string specifying the path to left directory.

right_path

A character string specifying the path to right directory.

Value

DT table showing the comparison between the two directories together with their synchronization status


Filter common files in a syncdr_status object based on specified criteria

Description

This function filters common files within a "syncdr_status" object, which is the result of 'compare_directories()', according to the specified filtering criteria: Filtering is dependent on the 'dir' argument, determining the primary directory for comparison

Usage

filter_common_files(
  sync_status,
  by_date = TRUE,
  by_content = FALSE,
  dir = "left"
)

Arguments

sync_status

An object of class 'syncdr_status' containing synchronization status and directory comparison results (common files only).

by_date

Logical; if TRUE, filters based on new files in the specified directory. Default is TRUE.

by_content

Logical; if TRUE, filters based on new or different files in the specified directory. Default is FALSE.

dir

Character vector specifying the primary directory for comparison ('left', 'right', or 'all').

Details

Filtering Options:

Value

A 'syncdr_status' object filtered according to the specified criteria.

See Also

compare_directories for directory comparison and sync status creation.


Filter files in a syncdr_status object that are NOT common between two directories compared

Description

This function filters files that are not common between the directories compared in the 'sync_status' object resulting from 'compare_directories()'.

Usage

filter_non_common_files(sync_status, dir = "left")

Arguments

sync_status

An object of class 'syncdr_status' containing information about synchronization status and directory comparisons.

dir

Character string specifying the directory to filter: - "left" for files unique to the left directory - "right" for files unique to the right directory - "all" for files unique to either directory

Value

An updated 'syncdr_status' object with filtered files according to the specified criteria.


Full asymmetric synchronization to right directory

Description

This function performs a full asymmetric synchronization of the right directory based on the left directory. It includes the following synchronization steps (see Details below):

Usage

full_asym_sync_to_right(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  by_date = TRUE,
  by_content = FALSE,
  recurse = TRUE,
  force = TRUE,
  delete_in_right = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

by_date

Logical. If TRUE, synchronize based on file modification dates (default is TRUE).

by_content

Logical. If TRUE, synchronize based on file contents (default is FALSE).

recurse

Logical. If TRUE (default), files are copied to corresponding subdirectories in the destination folder. If FALSE, files are copied to the top level of the destination folder without creating subdirectories if they do not exist.

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, Displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

delete_in_right

Logical. If TRUE (default), files that exist only in the right directory (i.e., absent from the left directory) are deleted during synchronization. If FALSE, no files are removed from the right directory, even if they are exclusive to it.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Details

Value

Invisible TRUE indicating successful synchronization.

Examples


e <- toy_dirs(fast = TRUE)
left  <- e$left
right <- e$right
full_asym_sync_to_right(
  left_path  = left,
  right_path = right,
  by_date    = FALSE,
  by_content = TRUE
)
sync_status <- compare_directories(left_path = left, right_path = right)
full_asym_sync_to_right(sync_status = sync_status)


Full symmetric synchronization

Description

This function updates directories in the following way:

Usage

full_symmetric_sync(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  by_date = TRUE,
  by_content = FALSE,
  recurse = TRUE,
  force = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

by_date

logical, TRUE by default

by_content

logical, FALSE by default

recurse

logical, TRUE by default. If recurse is TRUE: when copying a file from source folder to destination folder, the file will be copied into the corresponding (sub)directory. If the sub(directory) where the file is located does not exist in destination folder (or you are not sure), set recurse to FALSE, and the file will be copied at the top level

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Value

Invisible TRUE indicating successful synchronization.

Examples

# Create a temporary synchronization environment


e <- toy_dirs()
left  <- e$left
right <- e$right
# Symmetric synchronization by date and content
# Option 1: provide left and right paths
full_symmetric_sync(
  left_path  = left,
  right_path = right,
  by_date    = TRUE,
  by_content = TRUE
)

# Option 2: provide a precomputed sync_status object
sync_status <- compare_directories(
  left_path  = left,
  right_path = right
)
full_symmetric_sync(sync_status = sync_status)


Hash files by content

Description

Hash files by content

Usage

hash_files(files_path, verbose = getOption("syncdr.verbose"))

Arguments

files_path

character vector of paths of files to hash

verbose

logical; if TRUE display progress status of hashing. Default is FALSE

Value

hashes of files


Hash files in a directory based on content

Description

This function calculates hashes for files in a specified directory based on their content.

Usage

hash_files_in_dir(dir_path)

Arguments

dir_path

A character string of the path to the directory containing files for which hashes will be calculated

Value

A data frame containing file paths and their corresponding SHA-256 hashes.


Partial symmetric synchronization -common files only

Description

This function updates directories in the following way:

Usage

partial_symmetric_sync_common_files(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  by_date = TRUE,
  by_content = FALSE,
  recurse = TRUE,
  force = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

by_date

logical, TRUE by default

by_content

logical, FALSE by default

recurse

logical, TRUE by default. If recurse is TRUE: when copying a file from source folder to destination folder, the file will be copied into the corresponding (sub)directory. If the sub(directory) where the file is located does not exist in destination folder (or you are not sure), set recurse to FALSE, and the file will be copied at the top level

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Value

Invisible TRUE indicating successful synchronization.

Examples

# Create a temporary synchronization environment


e <- toy_dirs()
left  <- e$left
right <- e$right

# Partial symmetric synchronization of common files
# Option 1: provide left and right paths
partial_symmetric_sync_common_files(
  left_path  = left,
  right_path = right,
  by_date    = TRUE
)

# Option 2: provide a precomputed sync_status object
sync_status <- compare_directories(
  left_path  = left,
  right_path = right
)
partial_symmetric_sync_common_files(sync_status = sync_status)


Partial asymmetric asymmetric synchronization of non common files

Description

update non common files in right directory based on left one -i.e., the function will:

Usage

partial_update_missing_files_asym_to_right(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  recurse = TRUE,
  force = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

recurse

logical, TRUE by default. If recurse is TRUE: when copying a file from source folder to destination folder, the file will be copied into the corresponding (sub)directory. If the sub(directory) where the file is located does not exist in destination folder (or you are not sure), set recurse to FALSE, and the file will be copied at the top level

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, Displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Value

Invisible TRUE indicating successful synchronization.

Examples

# Create a temporary synchronization environment

e <- toy_dirs()
left  <- e$left
right <- e$right

# Partially update missing files asymmetrically (left → right)
# Option 1: provide left and right paths
partial_update_missing_files_asym_to_right(
  left_path  = left,
  right_path = right
)

# Option 2: provide a precomputed sync_status object
sync_status <- compare_directories(
  left_path  = left,
  right_path = right
)
partial_update_missing_files_asym_to_right(sync_status = sync_status)


Print Synchronization Status

Description

Print Synchronization Status

Usage

## S3 method for class 'syncdr_status'
print(x, ...)

Arguments

x

object of syncdr_status class created in compare_directories

...

additional arguments

Value

prints syncdr_status object


Set theme for colorDF

Description

Set theme for colorDF

Usage

rs_theme()

Value

invisible RStudio theme


Save sync_status file

Description

Save sync_status file

Usage

save_sync_status(dir_path)

Arguments

dir_path

path to directory

Value

the file is saved in a ⁠_syncdr⁠ subdirectory within the specified directory

Examples


# Set the directory path
e = toy_dirs()
left <- e$left

save_sync_status(dir_path = left)


Search for duplicate files in a directory

Description

This function searches for duplicate files within a directory based on their content. Duplicate files are identified by having either the same filename and same content or different filenames but same content.

Usage

search_duplicates(dir_path, verbose = TRUE)

Arguments

dir_path

A character string representing the path to the directory to search for duplicates

verbose

Logical. If TRUE, displays a list of duplicate files found (default is TRUE)

Value

A data frame containing information about duplicate files (invisible by default)

Examples

# Search for duplicate files in a directory


e <- toy_dirs()
search_duplicates(dir_path = e$left)


Apply Custom Style to Text

Description

This function applies a custom color and bold style to a given text string.

Usage

style_msgs(color_name, text)

Arguments

color_name

Character. Name of the color to apply. Each color name is associated with a specifically chosen color code. Available options for now are "pink", "blue", "purple", and "green".

text

Character. The text string to which the style will be applied.

Value

The styled text is printed to the console.


Create toy directories to test syncdr functions

Description

create directories in syncdr environment. Directories are deleted when a new R session is started

Usage

toy_dirs(verbose = FALSE, fast = FALSE)

Arguments

verbose

logical: display information. Default is FALSE

fast

logical: if TRUE (default), create a minimal set of files quickly; if FALSE, run full implementation with multiple files and timestamps.

Details

This function is a little slow because it must use Sys.sleep() to save files with the same name but different time stamp.

Value

syncdr environment with toy directory paths, i.e., left and right paths

Examples

# Create toy directories for testing / examples

toy_dirs(verbose = TRUE)


Full asymmetric synchronization of non common files

Description

update non common files in right directory based on left one -i.e., the function will:

Usage

update_missing_files_asym_to_right(
  left_path = NULL,
  right_path = NULL,
  sync_status = NULL,
  recurse = TRUE,
  force = TRUE,
  backup = FALSE,
  backup_dir = "temp_dir",
  copy_to_right = TRUE,
  delete_in_right = TRUE,
  exclude_delete = NULL,
  verbose = getOption("syncdr.verbose")
)

Arguments

left_path

Path to the left/first directory.

right_path

Path to the right/second directory.

sync_status

Object of class "syncdr_status", output of compare_directories().

recurse

logical, TRUE by default. If recurse is TRUE: when copying a file from source folder to destination folder, the file will be copied into the corresponding (sub)directory. If the sub(directory) where the file is located does not exist in destination folder (or you are not sure), set recurse to FALSE, and the file will be copied at the top level

force

Logical. If TRUE (by default), directly perform synchronization of the directories. If FALSE, Displays a preview of actions and prompts the user for confirmation before proceeding. Synchronization is aborted if the user does not agree.

backup

Logical. If TRUE, creates a backup of the right directory before synchronization. The backup is stored in the location specified by backup_dir.

backup_dir

Path to the directory where the backup of the original right directory will be stored. If not specified, the backup is stored in temporary directory (tempdir).

copy_to_right

Logical, default is TRUE. If TRUE, files that exist only in the left directory are copied to the right directory. If FALSE, such files are not copied and remain absent from the right directory.

delete_in_right

Logical, default is TRUE. If TRUE, files that exist only in the right directory (i.e., not present in the left) are deleted. If FALSE, these right-only files are preserved.

exclude_delete

Character vector of file names or dir names to protect from deletion. These files will be kept in the right directory even if delete = TRUE.

verbose

logical. If TRUE, display directory tree before and after synchronization. Default is FALSE

Value

Invisible TRUE indicating successful synchronization.

Examples

# Create a temporary synchronization environment

e <- toy_dirs()
left  <- e$left
right <- e$right

# Update missing files asymmetrically (left → right)
# Option 1: provide left and right paths
update_missing_files_asym_to_right(
  left_path  = left,
  right_path = right
)

# Option 2: provide a precomputed sync_status object
sync_status <- compare_directories(
  left_path  = left,
  right_path = right
)
update_missing_files_asym_to_right(sync_status = sync_status)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.