7
7
# '
8
8
# ' @param ... Arguments passed on to \code{stop}.
9
9
# ' @param domain The translation domain, NULL by default.
10
+ # '
10
11
# ' @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()]
12
15
# ' @examples
13
16
# ' \dontrun{
14
17
# ' stopp("This is a custom stop message without the call.")
@@ -27,12 +30,13 @@ stopp <- function(..., domain = NULL) {
27
30
# '
28
31
# ' @param ... Arguments passed on to \code{warning}.
29
32
# ' @return No return value, this function issues a warning.
33
+ # ' @export
34
+ # ' @keywords packageDevelopment
30
35
# ' @seealso \code{\link[base]{warning}}
31
36
# ' @examples
32
37
# ' \dontrun{
33
38
# ' warningp("This is a custom warning message without the call.")
34
39
# ' }
35
- # ' @export
36
40
warningp <- function (... ) {
37
41
do.call(base :: warning , args = append(list (call. = FALSE ), list (... )))
38
42
}
@@ -45,9 +49,9 @@ warningp <- function(...) {
45
49
# ' This function retrieves keywords from all package documentation files located
46
50
# ' in the `/man` directory of the specified R package. It can return a unique list
47
51
# ' of keywords or a frequency distribution of these keywords as a `table` object,
48
- # ' sorted by the keys.
52
+ # ' sorted by the keys.
49
53
# '
50
- # ' Note that it is far from perfect at the moment - it simply uses regex .
54
+ # ' Note that the "internal" keyword is ignored .
51
55
# '
52
56
# ' @param pkg The path to the R package directory.
53
57
# ' @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) {
78
82
return (character (0 ))
79
83
}
80
84
81
- getAllPkgKeywords(rdFiles ) %> %
85
+ getPkgKeywordsNoCheck(rdFiles , asDistribution )
86
+ }
87
+
88
+ getPkgKeywordsNoCheck <- function (
89
+ rdFiles , asDistribution , doErrorIfNoKw = FALSE
90
+ ) {
91
+
92
+ keywords <- getAllPkgKeywords(rdFiles ) %> %
82
93
ifelse(asDistribution , base :: table , base :: unique )() %> %
83
94
sort()
95
+
96
+ if (doErrorIfNoKw && (length(keywords ) == 0 )) {
97
+ stopp(" No keywords found in package documentation." )
98
+ }
99
+
100
+ keywords
84
101
}
85
102
86
- getAllPkgKeywords <- function (rdFilePaths ) {
103
+ getAllPkgKeywords <- function (rdFilePaths , doErrorIfNoKw = FALSE ) {
87
104
88
105
keywords <- character ()
89
106
@@ -99,100 +116,10 @@ getAllPkgKeywords <- function(rdFilePaths) {
99
116
}
100
117
}
101
118
119
+ keywords <- keywords [keywords != " internal" ]
102
120
keywords
103
121
}
104
122
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
-
196
123
# ' Get Existing File Path
197
124
# '
198
125
# ' This function checks whether a specified file exists within a given directory.
0 commit comments