Skip to content

Commit

Permalink
temporarily rm ymlkr
Browse files Browse the repository at this point in the history
  • Loading branch information
Qile0317 committed May 28, 2024
1 parent 2967dae commit 0373f54
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 196 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ License: MIT + file LICENSE
Encoding: UTF-8
Language: en-US
Imports:
cli,
devtools,
dplyr,
ggplot2,
hash,
Expand Down
4 changes: 1 addition & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ export(stopp)
export(stripSpaces)
export(substrEnd)
export(subtract)
export(sykr)
export(syncYMLKeywordRefs)
export(tableToNumeric)
export(test_quietly_that)
export(trySplitVarStr)
export(trySplit)
export(val)
export(val1)
export(warningp)
Expand Down
2 changes: 1 addition & 1 deletion R/color.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @export
#' @keywords color
#'
#' @source \url{https://stackoverflow.com/questions/649454}
#' @source <https://stackoverflow.com/questions/649454>
#'
#' @examples
#' getAvgHex("#00000", "#FF00FF")
Expand Down
121 changes: 24 additions & 97 deletions R/packageDevelopment.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#'
#' @param ... Arguments passed on to \code{stop}.
#' @param domain The translation domain, NULL by default.
#'
#' @return No return value, this function stops execution of the program.
#' @seealso \code{\link[base]{stop}}
#' @export
#' @keywords packageDevelopment
#' @seealso [stop()]
#' @examples
#' \dontrun{
#' stopp("This is a custom stop message without the call.")
Expand All @@ -27,12 +30,13 @@ stopp <- function(..., domain = NULL) {
#'
#' @param ... Arguments passed on to \code{warning}.
#' @return No return value, this function issues a warning.
#' @export
#' @keywords packageDevelopment
#' @seealso \code{\link[base]{warning}}
#' @examples
#' \dontrun{
#' warningp("This is a custom warning message without the call.")
#' }
#' @export
warningp <- function(...) {
do.call(base::warning, args = append(list(call. = FALSE), list(...)))
}
Expand All @@ -45,9 +49,9 @@ warningp <- function(...) {
#' This function retrieves keywords from all package documentation files located
#' in the `/man` directory of the specified R package. It can return a unique list
#' of keywords or a frequency distribution of these keywords as a `table` object,
#' sorted by the keys.
#' sorted by the keys.
#'
#' Note that it is far from perfect at the moment - it simply uses regex.
#' Note that the "internal" keyword is ignored.
#'
#' @param pkg The path to the R package directory.
#' @param asDistribution Logical; if FALSE, returns a character vector of unique keywords. If TRUE, returns a table with the frequency of each keyword.
Expand Down Expand Up @@ -78,12 +82,25 @@ getPkgKeywords <- function(pkg = ".", asDistribution = FALSE) {
return(character(0))
}

getAllPkgKeywords(rdFiles) %>%
getPkgKeywordsNoCheck(rdFiles, asDistribution)
}

getPkgKeywordsNoCheck <- function(
rdFiles, asDistribution, doErrorIfNoKw = FALSE
) {

keywords <- getAllPkgKeywords(rdFiles) %>%
ifelse(asDistribution, base::table, base::unique)() %>%
sort()

if (doErrorIfNoKw && (length(keywords) == 0)) {
stopp("No keywords found in package documentation.")
}

keywords
}

getAllPkgKeywords <- function(rdFilePaths) {
getAllPkgKeywords <- function(rdFilePaths, doErrorIfNoKw = FALSE) {

keywords <- character()

Expand All @@ -99,100 +116,10 @@ getAllPkgKeywords <- function(rdFilePaths) {
}
}

keywords <- keywords[keywords != "internal"]
keywords
}

# syncYMLKeywordRefs <- function(
# pkg = ".",
# ymlPath = "_pkgdown.yml",
# mode = c("a", "o"), # append or override
# sectionName = "reference",
# modifier = identity # TODO
# ) {

# fullYmlPath <- getExistingFilePath(dir = pkg, filePath = ymlPath)

# keywords <- getPkgKeywords(pkg = pkg, asDistribution = FALSE)
# if (length(keywords) == 0) {
# stop("No keywords found in package documentation.")
# }

# yamlContent <- yaml::read_yaml(fullYmlPath)

# # try find the section yamlContent[[sectionName]], else return addYMLKeywordRefs with the appropriate arguments and return
# # without nesting an else statement:
# # use the yml list object from yamlContent, and if mode is o, create the content list and append to the yamlContent[[sectionName]]
# # finally, write to the yaml with yaml::write_yaml
# }

#' Add or Sync Keyword References in Pkgdown YAML File
#'
#' Updates or creates the `_pkgdown.yml` file in a specified R package directory.
#' It appends or overwrites entries in a YAML section based on unique keywords extracted
#' from the package documentation, transformed using `trySplitVar` for more readable titles.
#'
#' @param pkg The path to the R package directory.
#' @param ymlPath The path to the `_pkgdown.yml` file, relative or absolute.
#' Default is "_pkgdown.yml" within the package directory.
#' @param mode Character string, "append" or "overwrite", determining how keywords are handled.
#' @param sectionName The name of the YAML section to modify. Default is "reference".
#' @param modifier A function to modify the keyword list; defaults to `trySplitVar`.
#' @export
#' @keywords packageDevelopment
syncYMLKeywordRefs <- function(
pkg = ".",
ymlPath = "_pkgdown.yml",
mode = "append",
sectionName = "reference",
modifier = trySplitVar
) {
stop("unfinished")
fullYmlPath <- getExistingFilePath(dir = pkg, filePath = ymlPath)
keywords <- getPkgKeywords(pkg = pkg)
if (length(keywords) == 0) {
stop("No keywords found in package documentation.")
}

modifiedKeywords <- lapply(keywords, modifier)

if (!file.exists(fullYmlPath)) {
yamlContent <- list()
} else {
yamlContent <- yaml::read_yaml(fullYmlPath)
}

if (mode == "overwrite") {
yamlContent[[sectionName]] <- list(keywords = unlist(modifiedKeywords))
} else { # append
existingKeywords <- yamlContent[[sectionName]]$keywords
if (is.null(existingKeywords)) existingKeywords <- list()
newKeywords <- unique(c(existingKeywords, unlist(modifiedKeywords)))
yamlContent[[sectionName]] <- list(keywords = newKeywords)
}

yaml::write_yaml(yamlContent, fullYmlPath)
}

#' @rdname syncYMLKeywordRefs
#' @export
sykr <- syncYMLKeywordRefs

# addYMLKeywordRefs
addYMLKeywordRefs <- function(
pkg = ".",
ymlPath = "_pkgdown.yml",
sectionName = "reference"
) {
fullYmlPath <- getExistingFilePath(dir = pkg, filePath = ymlPath)
keywords <- getPkgKeywords(pkg = pkg, asDistribution = FALSE)
if (length(keywords) == 0) {
stop("No keywords found in package documentation.")
}

# unfinished
stop("unfinished")
}

#' Get Existing File Path
#'
#' This function checks whether a specified file exists within a given directory.
Expand Down
34 changes: 19 additions & 15 deletions R/spelling.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#' Try to Split Variable Names Based on Naming Convention
#' Try to Split Names Based on Naming Convention
#'
#' This function attempts to split characters into its component words based on
#' camelCase, PascalCase, or snake_case conventions. If the string does not match
#' any of these conventions, it returns the original string.
#' This function attempts to split characters into its component words (and by default,
#' all in lowercase) based on camelCase, PascalCase, or snake_case conventions. If
#' the string does not match any of these conventions, it returns the original string.
#'
#' @param x A character string or vector to be analyzed and split.
#' @param conseq A logical indicating whether the `conseq` argument in [splitCamel()]/
#' [splitPascal()] should be `TRUE` or `FALSE`.
#' @param strictSnake A logical indicating the `strict` argument in [isSnakeCase()].
#' @param uncase A logical indicating whether to remove all casing in the output to
#' lowercase.
#'
#' @return A list of character vectors, each containing the parts of the string
#' split according to its naming convention or the original string if no
Expand All @@ -18,22 +20,24 @@
#' \code{\link{isCamelCase}}, \code{\link{isPascalCase}}, \code{\link{isSnakeCase}}
#'
#' @examples
#' trySplitVarStr("camelCaseExample")
#' trySplitVarStr("PascalCaseExample")
#' trySplitVarStr("snake_case_example")
#' trySplitVarStr("some|random|case")
#' trySplit("camelCaseExample")
#' trySplit("PascalCaseExample")
#' trySplit("snake_case_example")
#' trySplit("some|random|case")
#'
trySplitVarStr <- function(x, conseq = TRUE, strictSnake = FALSE) {
trySplit <- function(x, conseq = TRUE, strictSnake = FALSE, uncase = TRUE) {
lapply(x, function(y) {
if (isCamelCase(y) || isPascalCase(y)) {
return(unlist(splitCamel(y, conseq = isTRUE(conseq))))
out <- splitCamel(y, conseq = isTRUE(conseq))[[1]]
} else if (isSnakeCase(y, strict = isTRUE(strictSnake))) {
out <- splitSnake(y)[[1]]
} else {
out <- y
}
if (isSnakeCase(y, strict = isTRUE(strictSnake))) {
return(unlist(splitSnake(y)))
}
y
if (isTRUE(uncase)) return(tolower(out))
out
})
} # TODO test
}

#' Split CamelCase or PascalCase Strings
#'
Expand Down
53 changes: 27 additions & 26 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
url: https://qile0317.github.io/FastUtils/

template:
bootstrap: 5

development:
mode: auto

reference:
- title: math
- contents:
- has_keyword("math")
- title: spelling
- title: Character
- contents:
- has_keyword("spelling")
- title: wrangling
- has_keyword("character")
- title: Color
- contents:
- has_keyword("wrangling")
- title: dataInitialization
- has_keyword("color")
- title: Data Initialization
- contents:
- has_keyword("dataInitialization")
- title: higherOrderFunctions
- title: Ggplot
- contents:
- has_keyword("higherOrderFunctions")
- title: character
- has_keyword("ggplot")
- title: Higher Order Functions
- contents:
- has_keyword("character")
- title: iteration
- has_keyword("higherOrderFunctions")
- title: Indexing
- contents:
- has_keyword("iteration")
- title: internal
- has_keyword("indexing")
- title: Interactivity
- contents:
- has_keyword("internal")
- title: color
- has_keyword("interactivity")
- title: Iteration
- contents:
- has_keyword("color")
- title: indexing
- has_keyword("iteration")
- title: Math
- contents:
- has_keyword("indexing")
- title: packageDevelopment
- has_keyword("math")
- title: Package Development
- contents:
- has_keyword("packageDevelopment")
- title: ggplot
- title: Spelling
- contents:
- has_keyword("ggplot")
- title: testing
- has_keyword("spelling")
- title: Testing
- contents:
- has_keyword("testing")
- title: interactivity
- title: Wrangling
- contents:
- has_keyword("interactivity")
- has_keyword("wrangling")
2 changes: 1 addition & 1 deletion man/getPkgKeywords.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/stopp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions man/syncYMLKeywordRefs.Rd

This file was deleted.

Loading

0 comments on commit 0373f54

Please sign in to comment.