From 0c51a25511aadf8aae5f6577ccc658c14139c4bd Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 14 Sep 2024 16:15:27 -0400 Subject: [PATCH] updates --- R/brandfetch.R | 225 +++++++++++++++++++-------- R/generate_palette.R | 35 +++++ R/git_attributes.R | 15 ++ R/git_config.R | 13 ++ R/git_ignore.R | 13 ++ R/keyring.R | 4 +- R/noclocks_logo.R | 29 ++++ R/pdf.R | 2 +- R/shiny_assets.R | 55 +++++++ R/shiny_layouts.R | 37 +++++ R/shiny_resume.R | 6 +- R/utils_colors.R | 71 +++++++++ R/utils_images.R | 24 +++ R/utils_toggl.R | 122 +++++++++++++++ dev/functions.R | 68 +++++++- dev/pdf_processing.R | 2 +- dev/pkgdevt.R | 6 +- dev/vignettes.R | 6 +- inst/scripts/run_validation.R | 5 + man/git_attributes.Rd | 24 +++ man/git_config.Rd | 24 +++ man/git_ignore.Rd | 24 +++ man/hex_to_rgb.Rd | 22 +++ man/rgb_to_hex.Rd | 22 +++ man/rgba_to_hex.Rd | 33 ++++ man/time_tracking.Rd | 52 +++++++ tests/testthat/test-git_attributes.R | 3 + tests/testthat/test-git_config.R | 3 + tests/testthat/test-git_ignore.R | 3 + 29 files changed, 872 insertions(+), 76 deletions(-) create mode 100644 R/generate_palette.R create mode 100644 R/git_attributes.R create mode 100644 R/git_config.R create mode 100644 R/git_ignore.R create mode 100644 R/noclocks_logo.R create mode 100644 R/shiny_assets.R create mode 100644 R/shiny_layouts.R create mode 100644 R/utils_colors.R create mode 100644 R/utils_images.R create mode 100644 R/utils_toggl.R create mode 100644 inst/scripts/run_validation.R create mode 100644 man/git_attributes.Rd create mode 100644 man/git_config.Rd create mode 100644 man/git_ignore.Rd create mode 100644 man/hex_to_rgb.Rd create mode 100644 man/rgb_to_hex.Rd create mode 100644 man/rgba_to_hex.Rd create mode 100644 man/time_tracking.Rd create mode 100644 tests/testthat/test-git_attributes.R create mode 100644 tests/testthat/test-git_config.R create mode 100644 tests/testthat/test-git_ignore.R diff --git a/R/brandfetch.R b/R/brandfetch.R index 051c29c..68c1939 100644 --- a/R/brandfetch.R +++ b/R/brandfetch.R @@ -51,87 +51,186 @@ fetch_brand <- function( ) res <- req |> httr2::req_perform() + if (res$status_code != 200) { rlang::abort("Brandfetch API request failed") } + + # extract content --------------------------------------------------------- content <- res |> httr2::resp_body_json() - spec <- tibblify::tspec_object( + init_spec <- tibblify::tspec_row( tibblify::tib_chr("id"), tibblify::tib_chr("name"), tibblify::tib_chr("domain"), - tibblify::tib_lgl("claimed"), - tibblify::tib_chr("description"), - tibblify::tib_chr("longDescription"), - tibblify::tib_dbl("qualityScore"), - tibblify::tib_unspecified("images"), - - tibblify::tib_df( - "links", - tibblify::tib_chr("name"), - tibblify::tib_chr("url") - ), - - tibblify::tib_df( - "logos", - tibblify::tib_chr("theme"), - tibblify::tib_df( - "formats", - tibblify::tib_chr("src"), - tibblify::tib_unspecified("background"), - tibblify::tib_chr("format"), - tibblify::tib_int("height"), - tibblify::tib_int("width"), - tibblify::tib_int("size"), + tag_line = tibblify::tib_chr("description"), + description = tibblify::tib_chr("longDescription"), + quality_score = tibblify::tib_dbl("qualityScore") + ) + + brand_init <- tibblify::tibblify(content, init_spec) + + # links ------------------------------------------------------------------- + link_names <- content$links |> purrr::map_chr(purrr::pluck, "name") + link_urls <- content$links |> purrr::map_chr(purrr::pluck, "url") + + links <- tibble::tibble( + name = link_names, + url = link_urls + ) + + # logos ------------------------------------------------------------------- + logo_themes <- c() + logo_types <- c() + logo_urls <- c() + logo_backgrounds <- c() + logo_exts <- c() + logo_heights <- c() + logo_widths <- c() + logo_sizes <- c() + + logo_formats <- content$logos |> purrr::map(purrr::pluck, "formats") + + for (i in seq_along(content$logos)) { + + theme <- content$logos[[i]]$theme + type <- content$logos[[i]]$type + + formats <- content$logos[[i]]$formats + + for (j in seq_along(formats)) { + + url <- formats[[j]]$src + bg <- formats[[j]]$background + ext <- formats[[j]]$format + height <- formats[[j]]$height + width <- formats[[j]]$width + size <- formats[[j]]$size + + if (is.null(bg)) { bg <- NA_character_ } + if (ext == "svg") { + height <- NA_integer_ + width <- NA_integer_ + } + + logo_themes <- c(logo_themes, theme) + logo_types <- c(logo_types, type) + logo_urls <- c(logo_urls, url) + logo_backgrounds <- c(logo_backgrounds, bg) + logo_exts <- c(logo_exts, ext) + logo_heights <- c(logo_heights, height) + logo_widths <- c(logo_widths, width) + logo_sizes <- c(logo_sizes, size) + + } + + } + + logos <- tibble::tibble( + theme = logo_themes, + type = logo_types, + src = logo_urls, + background = logo_backgrounds, + ext = logo_exts, + height = logo_heights, + width = logo_widths, + size = logo_sizes + ) + + # colors ------------------------------------------------------------------ + colors_hex <- content$colors |> purrr::map_chr(purrr::pluck, "hex") + colors_type <- content$colors |> purrr::map_chr(purrr::pluck, "type") + colors_brightness <- content$colors |> purrr::map_int(purrr::pluck, "brightness") + + hex2rgb <- function(hex) { + hold <- grDevices::col2rgb(hex) + r <- hold[1] + g <- hold[2] + b <- hold[3] + out <- glue::glue( + "rgb({r}, {g}, {b})" + ) + out + } + + colors <- tibble::tibble( + hex = colors_hex, + type = colors_type, + brightness = colors_brightness + ) |> + dplyr::mutate( + rgb = purrr::map_chr(hex, hex2rgb) + ) + + # fonts ------------------------------------------------------------------- + fonts_name <- content$fonts |> purrr::map_chr(purrr::pluck, "name") + fonts_type <- content$fonts |> purrr::map_chr(purrr::pluck, "type") + fonts_origin <- content$fonts |> purrr::map_chr(purrr::pluck, "origin") + fonts_origin_id <- content$fonts |> purrr::map_chr(purrr::pluck, "originId") + + fonts <- tibble::tibble( + name = fonts_name, + type = fonts_type, + origin = fonts_origin, + origin_id = fonts_origin_id + ) |> + dplyr::mutate( + gfonts_url = paste0( + "https://fonts.google.com/specimen/", + name ), - tibblify::tib_unspecified("tags"), - tibblify::tib_chr("type") - ), - - tibblify::tib_df( - "colors", - tibblify::tib_chr("hex"), - tibblify::tib_chr("type"), - tibblify::tib_int("brightness"), - ), - - tibblify::tib_df( - "fonts", - tibblify::tib_chr("name"), - tibblify::tib_chr("type"), - tibblify::tib_chr("origin"), - tibblify::tib_chr("originId"), - tibblify::tib_unspecified("weights"), - ), - - tibblify::tib_row( - "company", - tibblify::tib_unspecified("employees"), - tibblify::tib_unspecified("foundedYear"), - tibblify::tib_unspecified("kind"), - tibblify::tib_unspecified("location"), - tibblify::tib_df( - "industries", - tibblify::tib_unspecified("id", required = FALSE), - tibblify::tib_unspecified("parent"), - tibblify::tib_dbl("score", required = FALSE), - tibblify::tib_chr("name", required = FALSE), - tibblify::tib_chr("emoji", required = FALSE), - tibblify::tib_chr("slug", required = FALSE) + import_css = paste0( + "@import url(", + stringr::str_c( + "https://fonts.googleapis.com/css2?family=", + name + ), + ");" ) ) - ) - out <- tibblify::tibblify(content, spec, unspecified = "drop") - out$logos <- out$logos |> tidyr::unnest("formats") - out$company <- out$company |> purrr::pluck("industries") + # company ----------------------------------------------------------------- + company <- content$company |> purrr::compact() - return(out) + industries <- company$industries + + industry_names <- industries |> purrr::map_chr(purrr::pluck, "name") + industry_emojis <- industries |> purrr::map_chr(purrr::pluck, "emoji") + industry_slugs <- industries |> purrr::map_chr(purrr::pluck, "slug") + industry_scores <- industries |> purrr::map_dbl(purrr::pluck, "score") + + company_industries <- tibble::tibble( + name = industry_names, + emoji = industry_emojis, + slug = industry_slugs, + score = industry_scores + ) |> + dplyr::arrange( + desc(score) + ) + + + # brand ------------------------------------------------------------------- + + brand <- brand_init |> + dplyr::mutate( + links = list(links), + logos = list(logos), + colors = list(colors), + fonts = list(fonts), + company = list(company_industries) + ) + + return(brand) } +# gmh_brand <- fetch_brand("gmhcommunities.com") +# brand_yml <- yaml::as.yaml(gmh_brand) +# yaml::write_yaml(gmh_brand, "dev/brandfetch/gmh_brand.yml") + #' Download Brand Logos #' #' @param brand Brand diff --git a/R/generate_palette.R b/R/generate_palette.R new file mode 100644 index 0000000..a60676c --- /dev/null +++ b/R/generate_palette.R @@ -0,0 +1,35 @@ +generate_palette_from_img <- function( + img_path, + num_colors = 40, + ... +) { + + paletter::create_palette( + image_path = img_path, + number_of_colors = num_colors, + ... + ) + +} + +generate_palette_from_color <- function( + color, + modification, + num_colors, + blend_color = NULL, + view_palette = TRUE, + view_labels = TRUE, + ... +) { + + monochromeR::generate_palette( + color = color, + modification = modification, + num_colors = num_colors, + blend_color = blend_color, + view_palette = view_palette, + view_labels = view_labels, + ... + ) + +} diff --git a/R/git_attributes.R b/R/git_attributes.R new file mode 100644 index 0000000..41a3bb4 --- /dev/null +++ b/R/git_attributes.R @@ -0,0 +1,15 @@ +#' Git Attributes +#' +#' @description +#' ... +#' +#' @param ... ... +#' +#' @return ... +#' +#' @export +#' +#' @example examples/ex_git_attributes.R +git_attributes <- function(...) { + +} diff --git a/R/git_config.R b/R/git_config.R new file mode 100644 index 0000000..a949b52 --- /dev/null +++ b/R/git_config.R @@ -0,0 +1,13 @@ +#' Git Config +#' +#' @description +#' ... +#' +#' @param ... ... +#' +#' @return ... +#' +#' @export +#' +#' @example examples/ex_git_config.R +git_config <- function(...) { } \ No newline at end of file diff --git a/R/git_ignore.R b/R/git_ignore.R new file mode 100644 index 0000000..9c6d082 --- /dev/null +++ b/R/git_ignore.R @@ -0,0 +1,13 @@ +#' Git Ignore +#' +#' @description +#' ... +#' +#' @param ... ... +#' +#' @return ... +#' +#' @export +#' +#' @example examples/ex_git_ignore.R +git_ignore <- function(...) { } diff --git a/R/keyring.R b/R/keyring.R index e8b1b51..ce17ef6 100644 --- a/R/keyring.R +++ b/R/keyring.R @@ -21,7 +21,7 @@ init_keyring <- function( msg <- glue::glue( "Keyring '{name}' created successfully.", - "To add secrets to the keyring, use `noclocksR::add_secret()`." + "To add secrets to the keyring, use `noclocksr::add_secret()`." ) rlang::inform(msg) @@ -71,7 +71,7 @@ check_keyring <- function( rlang::abort( glue::glue( "Keyring '{keyring}' does not exist.", - "Please create it using `noclocksR::init_keyring()`." + "Please create it using `noclocksr::init_keyring()`." ) ) } diff --git a/R/noclocks_logo.R b/R/noclocks_logo.R new file mode 100644 index 0000000..7668186 --- /dev/null +++ b/R/noclocks_logo.R @@ -0,0 +1,29 @@ + +# ------------------------------------------------------------------------ +# +# Title : No Clocks Logo +# By : Jimmy Briggs +# Date : 2024-07-26 +# +# ------------------------------------------------------------------------ + + +# internal ---------------------------------------------------------------- + + +# exported ---------------------------------------------------------------- + +# noclocks_logo <- function( +# type = c("symbol", "wordmark"), +# format = c("png", "svg", "jpeg", "webp", "gif"), +# height, +# width, +# ... +# ) { +# +# logos_root_dir <- pkg_sys_assets("logos") +# logo_dir <- fs::path(logos_root_dir, type, format) +# logo_file_name <- glue::glue("noclocks_logo_{type}.{format}") +# +# +# } diff --git a/R/pdf.R b/R/pdf.R index 408dc5a..9857b79 100644 --- a/R/pdf.R +++ b/R/pdf.R @@ -41,7 +41,7 @@ #' @examples #' \dontrun{ #' -#' fs::dir_copy(fs::path_package("noclocksR", "PDFs", "Input"), fs::path("Input")) +#' fs::dir_copy(fs::path_package("noclocksr", "PDFs", "Input"), fs::path("Input")) #' #' process_pdfs( #' input_dir = , diff --git a/R/shiny_assets.R b/R/shiny_assets.R new file mode 100644 index 0000000..950ab71 --- /dev/null +++ b/R/shiny_assets.R @@ -0,0 +1,55 @@ + +# ------------------------------------------------------------------------ +# +# Title : No Clocks R Shiny Assets +# By : Jimmy Briggs +# Date : 2024-07-26 +# +# ------------------------------------------------------------------------ + + +# internal ---------------------------------------------------------------- + +# https://www.jsdelivr.com/package/npm/js-cookie +.dep_jscookie <- htmltools::htmlDependency( + name = "js-cookie", + version = "3.0.5", + src = "https://cdn.jsdelivr.net/npm/js-cookie/dist/", + meta = NULL, + script = "js.cookie.min.js", + stylesheet = NULL, + head = NULL, + attachment = NULL, + package = NULL +) + +# noclocks dependencies --------------------------------------------------- + +noclocks_shiny_dependency <- function() { + htmltools::htmlDependency( + name = "noclocksShiny", + version = utils::packageVersion("noclocksr"), + src = c(href = "noclocksr", file = "assets"), + package = "noclocksr", + script = "noclocksShiny.script.min.js", + stylesheet = "noclocksShiny.styles.min.css", + all_files = FALSE + ) +} + +attach_noclocks_shiny_dependency <- function( + tag, + widget = NULL, + extra_deps = NULL +) { + + + deps <- noclocks_shiny_dependency() + + + + htmltools::attachDependencies( + htmltools::tagList(), + noclocks_shiny_dependency() + ) +} diff --git a/R/shiny_layouts.R b/R/shiny_layouts.R new file mode 100644 index 0000000..b773e47 --- /dev/null +++ b/R/shiny_layouts.R @@ -0,0 +1,37 @@ +# +# # ------------------------------------------------------------------------ +# # +# # Title : Shiny Layouts +# # By : Jimmy Briggs +# # Date : 2024-07-26 +# # +# # ------------------------------------------------------------------------ +# +# +# # internal ---------------------------------------------------------------- +# +# +# +# # dashboard page ---------------------------------------------------------- +# +# dash_page <- function( +# ..., +# dark = TRUE, +# title = NULL, +# theme = noclocks_shiny_theme(), +# favicon = noclocks_favicon() +# ) { +# +# head_tag <- htmltools::tags$head( +# +# ) +# +# } +# +# title, sidebar, body) { +# dashboardPage( +# dashboardHeader(title = title), +# dashboardSidebar(sidebar), +# dashboardBody(body) +# ) +# } diff --git a/R/shiny_resume.R b/R/shiny_resume.R index 59619b6..9019a23 100644 --- a/R/shiny_resume.R +++ b/R/shiny_resume.R @@ -6,12 +6,12 @@ shiny_resume_deps <- function() { "5.0.6", src = system.file( "shiny/startbootstrap-resume-gh-pages/", - package = "noclocksR" + package = "noclocksr" ), stylesheet = list.files( system.file( "shiny/startbootstrap-resume-gh-pages/", - package = "noclocksR" + package = "noclocksr" ), pattern = "\\.css$", recursive = TRUE @@ -19,7 +19,7 @@ shiny_resume_deps <- function() { script = list.files( system.file( "shiny/startbootstrap-resume-gh-pages/", - package = "noclocksR" + package = "noclocksr" ), pattern = "\\.js$", recursive = TRUE diff --git a/R/utils_colors.R b/R/utils_colors.R new file mode 100644 index 0000000..302065f --- /dev/null +++ b/R/utils_colors.R @@ -0,0 +1,71 @@ +#' Converts RGB values to hex colour code +#' +#' @param x A matrix of red, blue and green values +#' +#' @return A corresponding hex colour code +#' @export +#' +#' @examples temp_rgb_matrix <- rgba_to_rgb(c(52, 46, 39, 0.8)) +#' rgb_to_hex(temp_rgb_matrix) +#' +rgb_to_hex <- function(x){ + grDevices::rgb(x[1], x[2], x[3], maxColorValue = 255) +} + +#' Converts Hex codes values to RGB vectors +#' +#' @param x A hex colour code +#' +#' @return A corresponding matrix of red, blue and green values +#' @export +#' +#' @examples hex_to_rgb("purple") +#' hex_to_rgb("#fafafa") +#' +hex_to_rgb <- function(x){ + + temp_tibble <- as.data.frame(grDevices::col2rgb(x, alpha = FALSE)) + + paste0(c("r = ", "g = ", "b = "), temp_tibble$V1, + collapse = ", ") +} + +#' Convert RGB to HEX +#' +#' @param colour_rgba A vector of length 4: c(red value, green value, blue value, alpha). +#' All colour values must be between 0 and 255. Alpha must be between 0 and 1. +#' @param background_colour Defaults to white. Users can specify a different colour to get +#' the hex code for their original colour blended with a specified background colour. +#' `background_colour` must either be a recognised colour name (e.g. "white"), +#' a hex colour code (e.g. "#ffffff") or vector of length 3 (red value, green value, blue value), +#' with all values between 0 and 255. The default value is white ("#ffffff"). +#' @param ... Allows for US spelling of color/colour. +#' +#' @return Returns the corresponding hex colour code +#' @export +#' +#' @examples rgba_to_hex(c(52, 46, 39, 0.8)) +#' +#' rgba_to_hex(c(52, 46, 39, 0.8), "blue") +#' +#' rgba_to_hex(c(52, 46, 39, 0.8), "#032cfc") +rgba_to_hex <- function(colour_rgba, background_colour = "#ffffff", ...){ + + # Allows for US spelling input + check_dots <- list(...) + + if(missing(colour_rgba) & "color_rgba" %in% names(check_dots)) { + colour_rgba <- check_dots$color_rgba + } + + if("background_color" %in% names(check_dots)) { + background_colour <- check_dots$background_color + } + + new_col <- rgba_to_rgb(colour_rgba, background_colour) + + new_col_hex <- rgb_to_hex(new_col) + + return(new_col_hex) + +} diff --git a/R/utils_images.R b/R/utils_images.R new file mode 100644 index 0000000..f2ab73b --- /dev/null +++ b/R/utils_images.R @@ -0,0 +1,24 @@ +resize_crop_to_face <- function(image, size = 600) { + image <- resize_fit(image, size) + info <- image_info(image) + + # size may have changed after refit + size <- min(info$height, info$width) + + is_image_square <- info$width == info$height + if (is_image_square) { + return(image) + } + + face <- find_face_center(image) + + image_crop( + image, + geometry = geometry_area( + width = size, + height = size, + x_off = crop_offset(face$x, info$width, size), + y_off = crop_offset(face$y, info$height, size) + ) + ) +} diff --git a/R/utils_toggl.R b/R/utils_toggl.R new file mode 100644 index 0000000..25b42c7 --- /dev/null +++ b/R/utils_toggl.R @@ -0,0 +1,122 @@ + +# ------------------------------------------------------------------------ +# +# Title : Toggl Utilities +# By : Jimmy Briggs +# Date : 2024-09-05 +# +# ------------------------------------------------------------------------ + + +#' Toggl Time Tracking +#' +#' @name time_tracking +#' +#' @description +#' Functions for tracking time in the current project's context via Toggl. +#' +#' - `start_time_tracking()`: Start tracking time in Toggl. +#' - `stop_time_tracking()`: Stop tracking time in Toggl. +#' - `get_tracked_time()`: Retrieve tracked time entries from Toggl. +#' +#' @param description A description of the time entry. +#' Default is "R Development for GMH Leasing Dashboard" in this project. +#' @param tags A character vector of tags to apply to the time entry. +#' Note that if the project is billable, the "Billable" tag will be added. +#' @param config A configuration list for the Toggl project. +#' By default will retrieve values from the `toggl` configuration setup in +#' the `config.yml` for the project. +#' @param ... Additional arguments to pass to the various `togglr` functions. +#' +#' @return +#' - `start_time_tracking()`: The response from the Toggl API for starting time tracking. +#' - `stop_time_tracking()`: The response from the Toggl API for stopping time tracking. +#' - `get_tracked_time()`: A data frame of the time entries retrieved from Toggl. +NULL + +#' @rdname time_tracking +#' @export +#' @importFrom togglr toggl_start get_toggl_api_token set_toggl_api_token +#' @importFrom config get +#' @importFrom cli cli_bullets +start_time_tracking <- function( + description = "R Development for GMH Leasing Dashboard", + tags = c(), + config = config::get("toggl"), + ... +) { + + api_key <- togglr::get_toggl_api_token(ask = FALSE) + if (is.null(api_key)) { + api_key <- config$api_token + togglr::set_toggl_api_token(api_key) + } + + if (as.logical(config$is_billable) == TRUE) { + tags <- c("Billable", tags) + } + + res <- togglr::toggl_start( + description = description, + client = config$client_name, + project_name = config$project_name, + api_token = api_key, + tags = tags + ) + + cli::cli_bullets( + c( + "v" = "Time Tracking Started via Toggl (ID: {.field {res}})", + "i" = "Description: {.field {description}}", + "i" = "Client: {.field {config$client_name}}", + "i" = "Project: {.field {config$project_name}}", + "i" = "Tags: {.field {tags}}", + ">" = "To Stop Tracking run {.code stop_time_tracking()}" + ) + ) + + return(res) + +} + +#' @rdname time_tracking +#' @export +#' @importFrom togglr toggl_stop +#' @importFrom cli cli_abort cli_bullets +#' @importFrom rlang current_env +stop_time_tracking <- function(...) { + + call_env <- rlang::current_env() + + res <- tryCatch({ + togglr::toggl_stop(...) + }, error = function(e, call = call_env) { + cli::cli_abort( + c( + "Failed to stop time tracking via Toggl. Error: {.error {e}}", + "Are tou sure you started tracking time?" + ), + call = call + ) + }) + + cli::cli_bullets( + c( + "v" = "Time Tracking Stopped via Toggl", + ">" = "To view the time entry run {.code get_tracked_time()}" + ) + ) + +} + +#' @rdname time_tracking +#' @export +#' @importFrom lubridate weeks +#' @importFrom togglr get_time_entries +get_tracked_time <- function( + start = Sys.time() - lubridate::weeks(1), + end = Sys.time(), + ... +) { + togglr::get_time_entries(since = start, until = end, ...) +} diff --git a/dev/functions.R b/dev/functions.R index 53ab135..af8098f 100644 --- a/dev/functions.R +++ b/dev/functions.R @@ -1,3 +1,69 @@ new_function <- function( + name, + path = fs::path("R", glue::glue("{name}.R")), + title = stringr::str_to_title(stringr::str_replace(name, "_", " ")), + test = TRUE, + example = TRUE, + export = TRUE, + open = rlang::is_interactive() +) { + + # setup for test and example if necessary + if (test) { + test_path <- fs::path("tests", "testthat", glue::glue("test_{name}.R")) + usethis::use_test(name = name, open = FALSE) + } + + if (example) { + + example_path <- fs::path("examples", glue::glue("ex_{name}.R")) + example_roxy <- glue::glue("#' @example examples/ex_{name}.R\n") + example_content <- glue::glue( + "if (FALSE) {{\n\n", + " {name}()\n\n", + "}}\n" + ) + + if (!fs::dir_exists(fs::path("examples"))) { + fs::dir_create(fs::path("examples")) + cli::cli_alert_success("Created examples directory: {.path {fs::path('examples')}/}.") + } + + if (!fs::file_exists(example_path)) { + cat(example_content, file = example_path, sep = "\n") + cli::cli_alert_success("Created example file: {.path {example_path}}.") + } + + } + + # function skeleton + skeleton <- glue::glue( + "#' {title}", "\n", + "#'", "\n", + "#' @description", "\n", + "#'", " ...", "\n", + "#'", "\n", + "#' @param ... ...", "\n", + "#'", "\n", + "#' @return ...", "\n", + "#'", "\n", + if (export) { "#' @export\n" } else { "#' @keywords internal\n" }, + "#'", "\n", + if (example) { "#' @example examples/ex_{name}.R\n" }, + "{name} <- function(...) {{", + " ", + "}}" + ) + + # write to file + if (!fs::file_exists(path)) { + cat(skeleton, file = path) + cli::cli_alert_success("Created function file: {.path {path}}.") + } + + if (open) { + rstudioapi::navigateToFile(path) + } + +} -) diff --git a/dev/pdf_processing.R b/dev/pdf_processing.R index a80f91e..fb5f2a2 100644 --- a/dev/pdf_processing.R +++ b/dev/pdf_processing.R @@ -41,7 +41,7 @@ #' @examples #' \dontrun{ #' process_pdfs( -#' input_dir = fs::path_package("noclocksR", "PDFs"), +#' input_dir = fs::path_package("noclocksr", "PDFs"), #' output_dir = fs::path("output"), #' archive_dir = fs::path("archive"), #' log_file = fs::path("Logs", paste0(Sys.Date(), ".log")) diff --git a/dev/pkgdevt.R b/dev/pkgdevt.R index 7fc43b8..363950d 100644 --- a/dev/pkgdevt.R +++ b/dev/pkgdevt.R @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------ # -# Title : noclocksR Package Development Script +# Title : noclocksr Package Development Script # By : Jimmy Briggs # Date : 2024-02-07 # @@ -31,7 +31,7 @@ usethis::use_data_raw("client_demo_data") # initialize -------------------------------------------------------------- -usethis::create_package("noclocksR") +usethis::create_package("noclocksr") usethis::use_namespace() usethis::use_roxygen_md() usethis::use_git() @@ -108,7 +108,7 @@ usethis::use_rmarkdown_template( ) -usethis::use_vignette("noclocksR") +usethis::use_vignette("noclocksr") usethis::use_vignette("styleguide") usethis::use_vignette("shiny") diff --git a/dev/vignettes.R b/dev/vignettes.R index 711564a..124d2b6 100644 --- a/dev/vignettes.R +++ b/dev/vignettes.R @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------ # -# Title : noclocksR Package Vignettes +# Title : noclocksr Package Vignettes # By : Jimmy Briggs # Date : 2024-06-16 # @@ -17,7 +17,7 @@ require(rmarkdown) # vignettes --------------------------------------------------------------- c( - "noclocksR", + "noclocksr", "devenv", "pkgdevt", "shiny", @@ -30,3 +30,5 @@ c( purrr::walk( usethis::use_vignette ) + +usethis::use_vignette("naming-conventions") diff --git a/inst/scripts/run_validation.R b/inst/scripts/run_validation.R new file mode 100644 index 0000000..1c9b581 --- /dev/null +++ b/inst/scripts/run_validation.R @@ -0,0 +1,5 @@ +pkg_name <- read.dcf("DESCRIPTION")[, "Package"] +pkg_version <- read.dcf("DESCRIPTION")[, "Version"] + +test_results <- tibble::as_tibble(devtools::test()) + diff --git a/man/git_attributes.Rd b/man/git_attributes.Rd new file mode 100644 index 0000000..e2b353b --- /dev/null +++ b/man/git_attributes.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/git_attributes.R +\name{git_attributes} +\alias{git_attributes} +\title{Git Attributes} +\usage{ +git_attributes(...) +} +\arguments{ +\item{...}{...} +} +\value{ +... +} +\description{ +... +} +\examples{ +if (FALSE) { + + git_attributes() + +} +} diff --git a/man/git_config.Rd b/man/git_config.Rd new file mode 100644 index 0000000..b416b6c --- /dev/null +++ b/man/git_config.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/git_config.R +\name{git_config} +\alias{git_config} +\title{Git Config} +\usage{ +git_config(...) +} +\arguments{ +\item{...}{...} +} +\value{ +... +} +\description{ +... +} +\examples{ +if (FALSE) { + + git_config() + +} +} diff --git a/man/git_ignore.Rd b/man/git_ignore.Rd new file mode 100644 index 0000000..3db3e1c --- /dev/null +++ b/man/git_ignore.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/git_ignore.R +\name{git_ignore} +\alias{git_ignore} +\title{Git Ignore} +\usage{ +git_ignore(...) +} +\arguments{ +\item{...}{...} +} +\value{ +... +} +\description{ +... +} +\examples{ +if (FALSE) { + + git_ignore() + +} +} diff --git a/man/hex_to_rgb.Rd b/man/hex_to_rgb.Rd new file mode 100644 index 0000000..4ba0d3a --- /dev/null +++ b/man/hex_to_rgb.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_colors.R +\name{hex_to_rgb} +\alias{hex_to_rgb} +\title{Converts Hex codes values to RGB vectors} +\usage{ +hex_to_rgb(x) +} +\arguments{ +\item{x}{A hex colour code} +} +\value{ +A corresponding matrix of red, blue and green values +} +\description{ +Converts Hex codes values to RGB vectors +} +\examples{ +hex_to_rgb("purple") +hex_to_rgb("#fafafa") + +} diff --git a/man/rgb_to_hex.Rd b/man/rgb_to_hex.Rd new file mode 100644 index 0000000..f268984 --- /dev/null +++ b/man/rgb_to_hex.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_colors.R +\name{rgb_to_hex} +\alias{rgb_to_hex} +\title{Converts RGB values to hex colour code} +\usage{ +rgb_to_hex(x) +} +\arguments{ +\item{x}{A matrix of red, blue and green values} +} +\value{ +A corresponding hex colour code +} +\description{ +Converts RGB values to hex colour code +} +\examples{ +temp_rgb_matrix <- rgba_to_rgb(c(52, 46, 39, 0.8)) +rgb_to_hex(temp_rgb_matrix) + +} diff --git a/man/rgba_to_hex.Rd b/man/rgba_to_hex.Rd new file mode 100644 index 0000000..ec0a7f9 --- /dev/null +++ b/man/rgba_to_hex.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_colors.R +\name{rgba_to_hex} +\alias{rgba_to_hex} +\title{Convert RGB to HEX} +\usage{ +rgba_to_hex(colour_rgba, background_colour = "#ffffff", ...) +} +\arguments{ +\item{colour_rgba}{A vector of length 4: c(red value, green value, blue value, alpha). +All colour values must be between 0 and 255. Alpha must be between 0 and 1.} + +\item{background_colour}{Defaults to white. Users can specify a different colour to get +the hex code for their original colour blended with a specified background colour. +\code{background_colour} must either be a recognised colour name (e.g. "white"), +a hex colour code (e.g. "#ffffff") or vector of length 3 (red value, green value, blue value), +with all values between 0 and 255. The default value is white ("#ffffff").} + +\item{...}{Allows for US spelling of color/colour.} +} +\value{ +Returns the corresponding hex colour code +} +\description{ +Convert RGB to HEX +} +\examples{ +rgba_to_hex(c(52, 46, 39, 0.8)) + +rgba_to_hex(c(52, 46, 39, 0.8), "blue") + +rgba_to_hex(c(52, 46, 39, 0.8), "#032cfc") +} diff --git a/man/time_tracking.Rd b/man/time_tracking.Rd new file mode 100644 index 0000000..4ea09e0 --- /dev/null +++ b/man/time_tracking.Rd @@ -0,0 +1,52 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_toggl.R +\name{time_tracking} +\alias{time_tracking} +\alias{start_time_tracking} +\alias{stop_time_tracking} +\alias{get_tracked_time} +\title{Toggl Time Tracking} +\usage{ +start_time_tracking( + description = "R Development for GMH Leasing Dashboard", + tags = c(), + config = config::get("toggl"), + ... +) + +stop_time_tracking(...) + +get_tracked_time( + start = Sys.time() - lubridate::weeks(1), + end = Sys.time(), + ... +) +} +\arguments{ +\item{description}{A description of the time entry. +Default is "R Development for GMH Leasing Dashboard" in this project.} + +\item{tags}{A character vector of tags to apply to the time entry. +Note that if the project is billable, the "Billable" tag will be added.} + +\item{config}{A configuration list for the Toggl project. +By default will retrieve values from the \code{toggl} configuration setup in +the \code{config.yml} for the project.} + +\item{...}{Additional arguments to pass to the various \code{togglr} functions.} +} +\value{ +\itemize{ +\item \code{start_time_tracking()}: The response from the Toggl API for starting time tracking. +\item \code{stop_time_tracking()}: The response from the Toggl API for stopping time tracking. +\item \code{get_tracked_time()}: A data frame of the time entries retrieved from Toggl. +} +} +\description{ +Functions for tracking time in the current project's context via Toggl. +\itemize{ +\item \code{start_time_tracking()}: Start tracking time in Toggl. +\item \code{stop_time_tracking()}: Stop tracking time in Toggl. +\item \code{get_tracked_time()}: Retrieve tracked time entries from Toggl. +} +} diff --git a/tests/testthat/test-git_attributes.R b/tests/testthat/test-git_attributes.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-git_attributes.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) diff --git a/tests/testthat/test-git_config.R b/tests/testthat/test-git_config.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-git_config.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) diff --git a/tests/testthat/test-git_ignore.R b/tests/testthat/test-git_ignore.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-git_ignore.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +})