This function keeps the figure name unique by removing the older figures with the same name. Users can specify whether to keep the figure with the latest updated date or the latest created date. If a figure is created without changing, the created date and updated date are the same.

fd_unique(fdObj = fd_get_db(), by = "updated_date")

Arguments

fdObj

An object of class fdObj.

by

A character string specifying the method to keep the figure with the unique name. It can be either "updated_date" or "created_date".

Value

An object of class fdObj.

Examples

library(ggplot2)
## create ggfigdone database in a temporary directory
db_dir = file.path(tempdir(), "fd_unique")
fo = fd_init(db_dir, 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 = fo)
#> Automatic saving the ggfigdone data to the disk ...
#> [1] TRUE

## Add the another figure with the same name
fd_add(g = g + theme_classic(), name  = "fig1", fdObj = fo)
#> Automatic saving the ggfigdone data to the disk ...
#> [1] TRUE

## Keep the figure with the latest created date
fd_unique(fdObj = fo, by = "created_date")
#> 1 figures with the name 'fig1' are removed.
#> Automatic saving the ggfigdone data to the disk ...
#> ##########
#> ## ggfigdone database: /tmp/RtmpG9xoyp/fd_unique
#> ## Number of figures: 1
#> ## Last updated date: 2024-08-16 14:28:41

## Show the updated ggfigdone database
print(fo)
#> ##########
#> ## ggfigdone database: /tmp/RtmpG9xoyp/fd_unique
#> ## Number of figures: 1
#> ## Last updated date: 2024-08-16 14:28:41