diff --git a/DESCRIPTION b/DESCRIPTION index db60bfe..07695a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: typstcv Type: Package Title: CV for Quarto & Typst -Version: 0.0.1 +Version: 0.0.2 Authors@R: person(given = "Kazuharu", family = "Yanagimoto", diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..e08880d --- /dev/null +++ b/NEWS.md @@ -0,0 +1,9 @@ +## 0.0.2 + +Bug Fixes: + +- `format_date()` now correctly sorts after the formatting step. This was causing the dates to be sorted as strings, rather than as dates. + +## 0.0.1 + +- Initial GitHub submission \ No newline at end of file diff --git a/R/utils.R b/R/utils.R index d975b29..052fee1 100644 --- a/R/utils.R +++ b/R/utils.R @@ -14,6 +14,14 @@ #' @export #' #' @examples +#' work <- data.frame( +#' title = c("Technical Assistant", "Junior Professor", "Associate Professor"), +#' location = c("Bern, Switzerland", "Bern, Switzerland", "Zürich, Switzerland"), +#' start = as.Date(c("1902-01-01", "1908-01-01", "1909-01-01")), +#' end = as.Date(c("1908-01-01", "1909-01-01", "1911-01-01")), +#' description = c("Federal Patent Office", "University of Bern", "University of Zürich") +#' ) +#' #' work |> #' format_date(end = "end", date_format = "%Y", sort_by = "start") |> #' resume_entry() @@ -29,6 +37,18 @@ format_date <- function(data, sort_by = "none", decreasing = TRUE) { + # Sort + if (sort_by == "start") { + data <- data[order(data[[start]], decreasing = decreasing), ] + } else if (sort_by == "end" && !is.null(end)) { + data <- data[order(data[[end]], decreasing = decreasing), ] + } else if (sort_by == "none") { + # Do nothing + } else { + stop("Invalid sort_by value. Use 'none', 'start' or 'end'") + } + + # Format start date data[[start]] <- format(data[[start]], date_format) data[[start]][is.na(data[[start]])] <- replace_na @@ -41,16 +61,5 @@ format_date <- function(data, data[[colname_date]] <- paste(data[[start]], data[[end]], sep = sep) } - # Sort - if (sort_by == "start") { - data <- data[order(data[[start]], decreasing = decreasing), ] - } else if (sort_by == "end" && !is.null(end)) { - data <- data[order(data[[end]], decreasing = decreasing), ] - } else if (sort_by == "none") { - # Do nothing - } else { - stop("Invalid sort_by value. Use 'none', 'start' or 'end'") - } - return(data) } diff --git a/man/format_date.Rd b/man/format_date.Rd index c8b06de..8e09ddd 100644 --- a/man/format_date.Rd +++ b/man/format_date.Rd @@ -42,6 +42,14 @@ Data frame with formatted date column Data Column Formatter } \examples{ +work <- data.frame( + title = c("Technical Assistant", "Junior Professor", "Associate Professor"), + location = c("Bern, Switzerland", "Bern, Switzerland", "Zürich, Switzerland"), + start = as.Date(c("1902-01-01", "1908-01-01", "1909-01-01")), + end = as.Date(c("1908-01-01", "1909-01-01", "1911-01-01")), + description = c("Federal Patent Office", "University of Bern", "University of Zürich") +) + work |> format_date(end = "end", date_format = "\%Y", sort_by = "start") |> resume_entry()