Skip to content

Commit 7a8bcc1

Browse files
committed
Eliminate "class" from the parameter object
1 parent 12f8a28 commit 7a8bcc1

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

R/params.R

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#' @param text Character vector containing the document text
1010
#' @param evaluate If TRUE, expression values embedded within the YAML will be
1111
#' evaluated. This is the default. When FALSE, parameters defined by an
12-
#' expression will have the parsed expression in its \code{value} field and
13-
#' \code{"expression"} in the \code{class} field.
12+
#' expression will have the parsed expression in its \code{value} field.
1413
#'
1514
#' @return List of objects of class \code{knit_param} that correspond to the
1615
#' parameters declared in the \code{params} section of the YAML front matter.
@@ -19,7 +18,6 @@
1918
#' \describe{
2019
#' \item{\code{name}}{The parameter name.}
2120
#' \item{\code{value}}{The default value for the parameter.}
22-
#' \item{\code{class}}{The R class names of the parameter's default value.}
2321
#' \item{\code{expr}}{The R expression (if any) that yielded the default value.}
2422
#' }
2523
#'
@@ -93,8 +91,7 @@ knit_params = function(text, evaluate = TRUE) {
9391
#' @param yaml Character vector containing the YAML text
9492
#' @param evaluate If TRUE, expression values embedded within the YAML will be
9593
#' evaluated. This is the default. When FALSE, parameters defined by an
96-
#' expression will have the parsed expression in its \code{value} field and
97-
#' \code{"expression"} in the \code{class} field.
94+
#' expression will have the parsed expression in its \code{value} field.
9895
#'
9996
#' @return List of objects of class \code{knit_param} that correspond to the
10097
#' parameters declared in the \code{params} section of the YAML. See
@@ -273,16 +270,6 @@ resolve_params = function(params, evaluate = TRUE) {
273270
# normalize parameter value (i.e. strip attributes, list -> vector)
274271
param$value = param_value(param$value)
275272

276-
# record parameter class (must be explicit for null values)
277-
if (!is.null(param$value)) {
278-
param$class = class(param$value)
279-
} else {
280-
if (is.null(param$class))
281-
stop("no class field specified for YAML parameter '", name, "'",
282-
" (fields with a value of null must specify an explicit class)",
283-
call. = FALSE)
284-
}
285-
286273
# add knit_param class
287274
param = structure(param, class = "knit_param")
288275

man/knit_params.Rd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ knit_params(text, evaluate = TRUE)
1010

1111
\item{evaluate}{If TRUE, expression values embedded within the YAML will be
1212
evaluated. This is the default. When FALSE, parameters defined by an
13-
expression will have the parsed expression in its \code{value} field and
14-
\code{"expression"} in the \code{class} field.}
13+
expression will have the parsed expression in its \code{value} field.}
1514
}
1615
\value{
1716
List of objects of class \code{knit_param} that correspond to the
@@ -21,7 +20,6 @@ List of objects of class \code{knit_param} that correspond to the
2120
\describe{
2221
\item{\code{name}}{The parameter name.}
2322
\item{\code{value}}{The default value for the parameter.}
24-
\item{\code{class}}{The R class names of the parameter's default value.}
2523
\item{\code{expr}}{The R expression (if any) that yielded the default value.}
2624
}
2725

man/knit_params_yaml.Rd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ knit_params_yaml(yaml, evaluate = TRUE)
1010

1111
\item{evaluate}{If TRUE, expression values embedded within the YAML will be
1212
evaluated. This is the default. When FALSE, parameters defined by an
13-
expression will have the parsed expression in its \code{value} field and
14-
\code{"expression"} in the \code{class} field.}
13+
expression will have the parsed expression in its \code{value} field.}
1514
}
1615
\value{
1716
List of objects of class \code{knit_param} that correspond to the

tests/testit/test-params.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ params:
4040
'
4141
)
4242
assert(params[[1]]$name == 'start')
43-
assert('Date' %in% params[[1]]$class)
43+
assert('Date' %in% class(params[[1]]$value))
4444
assert(params[[1]]$value == as.Date("2015-01-01"))
4545
assert(params[[2]]$name == 'end')
46-
assert('POSIXct' %in% params[[2]]$class)
46+
assert('POSIXct' %in% class(params[[2]]$value))
4747
assert(params[[2]]$value == as.POSIXct("2015-01-01 12:30:00", tz = "GMT"))
4848

4949

@@ -124,9 +124,9 @@ params:
124124
'
125125
)
126126
assert(!is.null(params[[1]]$expr))
127-
assert('Date' %in% params[[1]]$class)
127+
assert('Date' %in% class(params[[1]]$value))
128128
assert(params[[2]]$expr)
129-
assert('POSIXct' %in% params[[2]]$class)
129+
assert('POSIXct' %in% class(params[[2]]$value))
130130
assert(is.null(params[[3]]$expr))
131131

132132
## test handling of unevaluated expressions --------------------------------------------
@@ -138,7 +138,6 @@ params:
138138
---
139139
', evaluate = FALSE)
140140
assert(identical(params$today$expr, "Sys.Date()"))
141-
assert(identical(params$today$class, "expression"))
142141
assert(identical(class(params$today$value), "expression"))
143142

144143
## test handling of yaml parameters --------------------------------------------
@@ -149,10 +148,9 @@ params:
149148
today: !r Sys.Date()
150149
')
151150
assert(params$x$value == 1)
152-
assert(identical(params$x$class, "integer"))
151+
assert(identical(class(params$x$value), "integer"))
153152
assert(identical(params$today$expr, "Sys.Date()"))
154-
assert('Date' %in% params$today$class)
155-
assert(identical(params$today$class, class(params$today$value)))
153+
assert('Date' %in% class(params$today$value))
156154

157155
## test handling of unevaluated yaml parameters --------------------------------------------
158156

@@ -161,6 +159,5 @@ params:
161159
today: !r Sys.Date()
162160
', evaluate = FALSE)
163161
assert(identical(params$today$expr, "Sys.Date()"))
164-
assert(identical(params$today$class, "expression"))
165162
assert(identical(class(params$today$value), "expression"))
166163

0 commit comments

Comments
 (0)