Skip to content

Commit 0373f54

Browse files
committed
temporarily rm ymlkr
1 parent 2967dae commit 0373f54

File tree

12 files changed

+231
-196
lines changed

12 files changed

+231
-196
lines changed

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ License: MIT + file LICENSE
1111
Encoding: UTF-8
1212
Language: en-US
1313
Imports:
14+
cli,
15+
devtools,
1416
dplyr,
1517
ggplot2,
1618
hash,

NAMESPACE

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ export(stopp)
4646
export(stripSpaces)
4747
export(substrEnd)
4848
export(subtract)
49-
export(sykr)
50-
export(syncYMLKeywordRefs)
5149
export(tableToNumeric)
5250
export(test_quietly_that)
53-
export(trySplitVarStr)
51+
export(trySplit)
5452
export(val)
5553
export(val1)
5654
export(warningp)

R/color.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @export
1111
#' @keywords color
1212
#'
13-
#' @source \url{https://stackoverflow.com/questions/649454}
13+
#' @source <https://stackoverflow.com/questions/649454>
1414
#'
1515
#' @examples
1616
#' getAvgHex("#00000", "#FF00FF")

R/packageDevelopment.R

Lines changed: 24 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
#'
88
#' @param ... Arguments passed on to \code{stop}.
99
#' @param domain The translation domain, NULL by default.
10+
#'
1011
#' @return No return value, this function stops execution of the program.
11-
#' @seealso \code{\link[base]{stop}}
12+
#' @export
13+
#' @keywords packageDevelopment
14+
#' @seealso [stop()]
1215
#' @examples
1316
#' \dontrun{
1417
#' stopp("This is a custom stop message without the call.")
@@ -27,12 +30,13 @@ stopp <- function(..., domain = NULL) {
2730
#'
2831
#' @param ... Arguments passed on to \code{warning}.
2932
#' @return No return value, this function issues a warning.
33+
#' @export
34+
#' @keywords packageDevelopment
3035
#' @seealso \code{\link[base]{warning}}
3136
#' @examples
3237
#' \dontrun{
3338
#' warningp("This is a custom warning message without the call.")
3439
#' }
35-
#' @export
3640
warningp <- function(...) {
3741
do.call(base::warning, args = append(list(call. = FALSE), list(...)))
3842
}
@@ -45,9 +49,9 @@ warningp <- function(...) {
4549
#' This function retrieves keywords from all package documentation files located
4650
#' in the `/man` directory of the specified R package. It can return a unique list
4751
#' of keywords or a frequency distribution of these keywords as a `table` object,
48-
#' sorted by the keys.
52+
#' sorted by the keys.
4953
#'
50-
#' Note that it is far from perfect at the moment - it simply uses regex.
54+
#' Note that the "internal" keyword is ignored.
5155
#'
5256
#' @param pkg The path to the R package directory.
5357
#' @param asDistribution Logical; if FALSE, returns a character vector of unique keywords. If TRUE, returns a table with the frequency of each keyword.
@@ -78,12 +82,25 @@ getPkgKeywords <- function(pkg = ".", asDistribution = FALSE) {
7882
return(character(0))
7983
}
8084

81-
getAllPkgKeywords(rdFiles) %>%
85+
getPkgKeywordsNoCheck(rdFiles, asDistribution)
86+
}
87+
88+
getPkgKeywordsNoCheck <- function(
89+
rdFiles, asDistribution, doErrorIfNoKw = FALSE
90+
) {
91+
92+
keywords <- getAllPkgKeywords(rdFiles) %>%
8293
ifelse(asDistribution, base::table, base::unique)() %>%
8394
sort()
95+
96+
if (doErrorIfNoKw && (length(keywords) == 0)) {
97+
stopp("No keywords found in package documentation.")
98+
}
99+
100+
keywords
84101
}
85102

86-
getAllPkgKeywords <- function(rdFilePaths) {
103+
getAllPkgKeywords <- function(rdFilePaths, doErrorIfNoKw = FALSE) {
87104

88105
keywords <- character()
89106

@@ -99,100 +116,10 @@ getAllPkgKeywords <- function(rdFilePaths) {
99116
}
100117
}
101118

119+
keywords <- keywords[keywords != "internal"]
102120
keywords
103121
}
104122

105-
# syncYMLKeywordRefs <- function(
106-
# pkg = ".",
107-
# ymlPath = "_pkgdown.yml",
108-
# mode = c("a", "o"), # append or override
109-
# sectionName = "reference",
110-
# modifier = identity # TODO
111-
# ) {
112-
113-
# fullYmlPath <- getExistingFilePath(dir = pkg, filePath = ymlPath)
114-
115-
# keywords <- getPkgKeywords(pkg = pkg, asDistribution = FALSE)
116-
# if (length(keywords) == 0) {
117-
# stop("No keywords found in package documentation.")
118-
# }
119-
120-
# yamlContent <- yaml::read_yaml(fullYmlPath)
121-
122-
# # try find the section yamlContent[[sectionName]], else return addYMLKeywordRefs with the appropriate arguments and return
123-
# # without nesting an else statement:
124-
# # use the yml list object from yamlContent, and if mode is o, create the content list and append to the yamlContent[[sectionName]]
125-
# # finally, write to the yaml with yaml::write_yaml
126-
# }
127-
128-
#' Add or Sync Keyword References in Pkgdown YAML File
129-
#'
130-
#' Updates or creates the `_pkgdown.yml` file in a specified R package directory.
131-
#' It appends or overwrites entries in a YAML section based on unique keywords extracted
132-
#' from the package documentation, transformed using `trySplitVar` for more readable titles.
133-
#'
134-
#' @param pkg The path to the R package directory.
135-
#' @param ymlPath The path to the `_pkgdown.yml` file, relative or absolute.
136-
#' Default is "_pkgdown.yml" within the package directory.
137-
#' @param mode Character string, "append" or "overwrite", determining how keywords are handled.
138-
#' @param sectionName The name of the YAML section to modify. Default is "reference".
139-
#' @param modifier A function to modify the keyword list; defaults to `trySplitVar`.
140-
#' @export
141-
#' @keywords packageDevelopment
142-
syncYMLKeywordRefs <- function(
143-
pkg = ".",
144-
ymlPath = "_pkgdown.yml",
145-
mode = "append",
146-
sectionName = "reference",
147-
modifier = trySplitVar
148-
) {
149-
stop("unfinished")
150-
fullYmlPath <- getExistingFilePath(dir = pkg, filePath = ymlPath)
151-
keywords <- getPkgKeywords(pkg = pkg)
152-
if (length(keywords) == 0) {
153-
stop("No keywords found in package documentation.")
154-
}
155-
156-
modifiedKeywords <- lapply(keywords, modifier)
157-
158-
if (!file.exists(fullYmlPath)) {
159-
yamlContent <- list()
160-
} else {
161-
yamlContent <- yaml::read_yaml(fullYmlPath)
162-
}
163-
164-
if (mode == "overwrite") {
165-
yamlContent[[sectionName]] <- list(keywords = unlist(modifiedKeywords))
166-
} else { # append
167-
existingKeywords <- yamlContent[[sectionName]]$keywords
168-
if (is.null(existingKeywords)) existingKeywords <- list()
169-
newKeywords <- unique(c(existingKeywords, unlist(modifiedKeywords)))
170-
yamlContent[[sectionName]] <- list(keywords = newKeywords)
171-
}
172-
173-
yaml::write_yaml(yamlContent, fullYmlPath)
174-
}
175-
176-
#' @rdname syncYMLKeywordRefs
177-
#' @export
178-
sykr <- syncYMLKeywordRefs
179-
180-
# addYMLKeywordRefs
181-
addYMLKeywordRefs <- function(
182-
pkg = ".",
183-
ymlPath = "_pkgdown.yml",
184-
sectionName = "reference"
185-
) {
186-
fullYmlPath <- getExistingFilePath(dir = pkg, filePath = ymlPath)
187-
keywords <- getPkgKeywords(pkg = pkg, asDistribution = FALSE)
188-
if (length(keywords) == 0) {
189-
stop("No keywords found in package documentation.")
190-
}
191-
192-
# unfinished
193-
stop("unfinished")
194-
}
195-
196123
#' Get Existing File Path
197124
#'
198125
#' This function checks whether a specified file exists within a given directory.

R/spelling.R

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
#' Try to Split Variable Names Based on Naming Convention
1+
#' Try to Split Names Based on Naming Convention
22
#'
3-
#' This function attempts to split characters into its component words based on
4-
#' camelCase, PascalCase, or snake_case conventions. If the string does not match
5-
#' any of these conventions, it returns the original string.
3+
#' This function attempts to split characters into its component words (and by default,
4+
#' all in lowercase) based on camelCase, PascalCase, or snake_case conventions. If
5+
#' the string does not match any of these conventions, it returns the original string.
66
#'
77
#' @param x A character string or vector to be analyzed and split.
88
#' @param conseq A logical indicating whether the `conseq` argument in [splitCamel()]/
99
#' [splitPascal()] should be `TRUE` or `FALSE`.
1010
#' @param strictSnake A logical indicating the `strict` argument in [isSnakeCase()].
11+
#' @param uncase A logical indicating whether to remove all casing in the output to
12+
#' lowercase.
1113
#'
1214
#' @return A list of character vectors, each containing the parts of the string
1315
#' split according to its naming convention or the original string if no
@@ -18,22 +20,24 @@
1820
#' \code{\link{isCamelCase}}, \code{\link{isPascalCase}}, \code{\link{isSnakeCase}}
1921
#'
2022
#' @examples
21-
#' trySplitVarStr("camelCaseExample")
22-
#' trySplitVarStr("PascalCaseExample")
23-
#' trySplitVarStr("snake_case_example")
24-
#' trySplitVarStr("some|random|case")
23+
#' trySplit("camelCaseExample")
24+
#' trySplit("PascalCaseExample")
25+
#' trySplit("snake_case_example")
26+
#' trySplit("some|random|case")
2527
#'
26-
trySplitVarStr <- function(x, conseq = TRUE, strictSnake = FALSE) {
28+
trySplit <- function(x, conseq = TRUE, strictSnake = FALSE, uncase = TRUE) {
2729
lapply(x, function(y) {
2830
if (isCamelCase(y) || isPascalCase(y)) {
29-
return(unlist(splitCamel(y, conseq = isTRUE(conseq))))
31+
out <- splitCamel(y, conseq = isTRUE(conseq))[[1]]
32+
} else if (isSnakeCase(y, strict = isTRUE(strictSnake))) {
33+
out <- splitSnake(y)[[1]]
34+
} else {
35+
out <- y
3036
}
31-
if (isSnakeCase(y, strict = isTRUE(strictSnake))) {
32-
return(unlist(splitSnake(y)))
33-
}
34-
y
37+
if (isTRUE(uncase)) return(tolower(out))
38+
out
3539
})
36-
} # TODO test
40+
}
3741

3842
#' Split CamelCase or PascalCase Strings
3943
#'

_pkgdown.yml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
url: https://qile0317.github.io/FastUtils/
2+
23
template:
34
bootstrap: 5
45

6+
development:
7+
mode: auto
8+
59
reference:
6-
- title: math
7-
- contents:
8-
- has_keyword("math")
9-
- title: spelling
10+
- title: Character
1011
- contents:
11-
- has_keyword("spelling")
12-
- title: wrangling
12+
- has_keyword("character")
13+
- title: Color
1314
- contents:
14-
- has_keyword("wrangling")
15-
- title: dataInitialization
15+
- has_keyword("color")
16+
- title: Data Initialization
1617
- contents:
1718
- has_keyword("dataInitialization")
18-
- title: higherOrderFunctions
19+
- title: Ggplot
1920
- contents:
20-
- has_keyword("higherOrderFunctions")
21-
- title: character
21+
- has_keyword("ggplot")
22+
- title: Higher Order Functions
2223
- contents:
23-
- has_keyword("character")
24-
- title: iteration
24+
- has_keyword("higherOrderFunctions")
25+
- title: Indexing
2526
- contents:
26-
- has_keyword("iteration")
27-
- title: internal
27+
- has_keyword("indexing")
28+
- title: Interactivity
2829
- contents:
29-
- has_keyword("internal")
30-
- title: color
30+
- has_keyword("interactivity")
31+
- title: Iteration
3132
- contents:
32-
- has_keyword("color")
33-
- title: indexing
33+
- has_keyword("iteration")
34+
- title: Math
3435
- contents:
35-
- has_keyword("indexing")
36-
- title: packageDevelopment
36+
- has_keyword("math")
37+
- title: Package Development
3738
- contents:
3839
- has_keyword("packageDevelopment")
39-
- title: ggplot
40+
- title: Spelling
4041
- contents:
41-
- has_keyword("ggplot")
42-
- title: testing
42+
- has_keyword("spelling")
43+
- title: Testing
4344
- contents:
4445
- has_keyword("testing")
45-
- title: interactivity
46+
- title: Wrangling
4647
- contents:
47-
- has_keyword("interactivity")
48+
- has_keyword("wrangling")

man/getPkgKeywords.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/stopp.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/syncYMLKeywordRefs.Rd

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)