This function merges two ggfigdone databases. The function will update the figures in the 'to' database with the figures in the 'from' database. If there is a figure with the same ID in both databases, the function will keep the figure with the latest updated date or created date.
fd_merge(from, to = fd_get_db(), replace = "updated_date")
An object of class fdObj
with the merged database.
library(ggplot2)
## create ggfigdone database in a temporary directory
db_dir1 = file.path(tempdir(), "db1")
db_dir2 = file.path(tempdir(), "db2")
fo1 = fd_init(db_dir1, rm_exist = TRUE)
#> The database version is up-to-date.
fo2 = fd_init(db_dir2, rm_exist = TRUE)
#> The database version is up-to-date.
## Draw a ggplot figure
g = ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()
## Add the figure to the database
fd_add(g = g, name = "fig1", fdObj = fo1)
#> Automatic saving the ggfigdone data to the disk ...
#> [1] TRUE
fd_add(g = g + theme_classic(), name = "fig2", fdObj = fo2)
#> Automatic saving the ggfigdone data to the disk ...
#> [1] TRUE
## Merge the databases
fo_merge = fd_merge(from = fo1, to = fo2, replace = "updated_date")
## Show the updated ggfigdone database
print(fo_merge)
#> ##########
#> ## ggfigdone database: /tmp/RtmpG9xoyp/db2
#> ## Number of figures: 2
#> ## Last updated date: 2024-08-16 14:28:39
##