Skip to content

Commit 2052682

Browse files
committed
Update embedded yaml
1 parent ef84d8c commit 2052682

File tree

16 files changed

+528
-89
lines changed

16 files changed

+528
-89
lines changed

src/library/yaml/COPYING

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
R YAML package
22
==============
33

4-
Copyright (c) 2008-2016 Vanderbilt University
5-
Copyright (c) 2016-2018 Vanderbilt University Medical Center
4+
Copyright (c) 2008-2025 Vanderbilt University
65

76
Redistribution and use in source and binary forms, with or without
87
modification, are permitted provided that the following conditions are

src/library/yaml/DESCRIPTION

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
1-
Package: yaml
21
Type: Package
2+
Package: yaml
33
Title: Methods to Convert R Data to YAML and Back
4-
Date: 2024-07-22
5-
Version: 2.3.10
6-
Suggests: RUnit
7-
Author: Shawn P Garbett [aut], Jeremy Stephens [aut, cre], Kirill Simonov [aut], Yihui Xie [ctb],
8-
Zhuoer Dong [ctb], Hadley Wickham [ctb], Jeffrey Horner [ctb], reikoch [ctb],
9-
Will Beasley [ctb], Brendan O'Connor [ctb], Gregory R. Warnes [ctb],
10-
Michael Quinn [ctb], Zhian N. Kamvar [ctb], Charlie Gao [ctb]
11-
Maintainer: Shawn Garbett <[email protected]>
12-
License: BSD_3_clause + file LICENSE
4+
Version: 2.3.12
5+
Authors@R: c(
6+
person("Hadley", "Wickham", , "[email protected]", role = "cre",
7+
comment = c(ORCID = "0000-0003-4757-117X")),
8+
person("Shawn", "Garbett", , "[email protected]", role = "ctb",
9+
comment = c(ORCID = "0000-0003-4079-5621")),
10+
person("Jeremy", "Stephens", role = c("aut", "ctb")),
11+
person("Kirill", "Simonov", role = "aut"),
12+
person("Yihui", "Xie", role = "ctb",
13+
comment = c(ORCID = "0000-0003-0645-5666")),
14+
person("Zhuoer", "Dong", role = "ctb"),
15+
person("Jeffrey", "Horner", role = "ctb"),
16+
person("reikoch", role = "ctb"),
17+
person("Will", "Beasley", role = "ctb",
18+
comment = c(ORCID = "0000-0002-5613-5006")),
19+
person("Brendan", "O'Connor", role = "ctb"),
20+
person("Michael", "Quinn", role = "ctb"),
21+
person("Charlie", "Gao", role = "ctb"),
22+
person(c("Gregory", "R."), "Warnes", role = "ctb"),
23+
person(c("Zhian", "N."), "Kamvar", role = "ctb")
24+
)
1325
Description: Implements the 'libyaml' 'YAML' 1.1 parser and emitter
14-
(<https://pyyaml.org/wiki/LibYAML>) for R.
15-
URL: https://github.com/vubiostat/r-yaml/
16-
BugReports: https://github.com/vubiostat/r-yaml/issues
26+
(<https://pyyaml.org/wiki/LibYAML>) for R.
27+
License: BSD_3_clause + file LICENSE
28+
URL: https://yaml.r-lib.org, https://github.com/r-lib/yaml/
29+
BugReports: https://github.com/r-lib/yaml/issues
30+
Suggests: knitr, rmarkdown, testthat (>= 3.0.0)
31+
Config/testthat/edition: 3
32+
Config/Needs/website: tidyverse/tidytemplate
33+
Encoding: UTF-8
34+
RoxygenNote: 7.3.3
35+
VignetteBuilder: knitr
1736
NeedsCompilation: yes
18-
Packaged: 2024-07-22 15:44:18 UTC; garbetsp
37+
Packaged: 2025-12-08 16:53:07 UTC; hadleywickham
38+
Author: Hadley Wickham [cre] (ORCID: <https://orcid.org/0000-0003-4757-117X>),
39+
Shawn Garbett [ctb] (ORCID: <https://orcid.org/0000-0003-4079-5621>),
40+
Jeremy Stephens [aut, ctb],
41+
Kirill Simonov [aut],
42+
Yihui Xie [ctb] (ORCID: <https://orcid.org/0000-0003-0645-5666>),
43+
Zhuoer Dong [ctb],
44+
Jeffrey Horner [ctb],
45+
reikoch [ctb],
46+
Will Beasley [ctb] (ORCID: <https://orcid.org/0000-0002-5613-5006>),
47+
Brendan O'Connor [ctb],
48+
Michael Quinn [ctb],
49+
Charlie Gao [ctb],
50+
Gregory R. Warnes [ctb],
51+
Zhian N. Kamvar [ctb]
52+
Maintainer: Hadley Wickham <[email protected]>
1953
Repository: CRAN
20-
Date/Publication: 2024-07-26 15:10:02 UTC
54+
Date/Publication: 2025-12-10 07:00:01 UTC

src/library/yaml/LICENSE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
YEAR: 2008-2022
2-
COPYRIGHT HOLDER: Vanderbilt University Medical Center
3-
ORGANIZATION: Vanderbilt University Medical Center
1+
YEAR: 2008-2025
2+
COPYRIGHT HOLDER: Vanderbilt University
3+
ORGANIZATION: Vanderbilt University

src/library/yaml/NAMESPACE

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(as.yaml)
4+
export(read_yaml)
5+
export(verbatim_logical)
6+
export(write_yaml)
7+
export(yaml.load)
8+
export(yaml.load_file)
19
useDynLib(yaml, .registration = TRUE, .fixes = "C_")
2-
export(as.yaml, yaml.load_file, yaml.load, read_yaml, write_yaml, verbatim_logical)

src/library/yaml/R/as.yaml.R

Lines changed: 138 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,142 @@
1-
`as.yaml` <-
2-
function(x, line.sep = c('\n', '\r\n', '\r'), indent = 2, omap = FALSE,
3-
column.major = TRUE, unicode = TRUE, precision = getOption('digits'),
4-
indent.mapping.sequence = FALSE, handlers = NULL) {
5-
1+
#' Convert an R object into a YAML string
2+
#'
3+
#' If you set the `omap` option to TRUE, as.yaml will create ordered maps
4+
#' (or omaps) instead of normal maps.
5+
#'
6+
#' The `column.major` option determines how a data frame is converted. If
7+
#' TRUE, the data frame is converted into a map of sequences where the name of
8+
#' each column is a key. If FALSE, the data frame is converted into a sequence
9+
#' of maps, where each element in the sequence is a row. You'll probably
10+
#' almost always want to leave this as TRUE (which is the default), because
11+
#' using [yaml.load()] on the resulting string returns an object
12+
#' which is much more easily converted into a data frame via
13+
#' [as.data.frame()].
14+
#'
15+
#' You can specify custom handler functions via the `handlers` argument.
16+
#' This argument must be a named list of functions, where the names are R
17+
#' object class names (i.e., 'numeric', 'data.frame', 'list', etc). The
18+
#' function(s) you provide will be passed one argument (the R object) and can
19+
#' return any R object. The returned object will be emitted normally.
20+
#'
21+
#' Character vectors that have a class of \sQuote{verbatim} will not be quoted
22+
#' in the output YAML document except when the YAML specification requires it.
23+
#' This means that you cannot do anything that would result in an invalid YAML
24+
#' document, but you can emit strings that would otherwise be quoted. This is
25+
#' useful for changing how logical vectors are emitted (see below for example).
26+
#'
27+
#' Character vectors that have an attribute of \sQuote{quoted} will be wrapped
28+
#' in double quotes (see below for example).
29+
#'
30+
#' You can specify YAML tags for R objects by setting the \sQuote{tag}
31+
#' attribute to a character vector of length 1. If you set a tag for a vector,
32+
#' the tag will be applied to the YAML sequence as a whole, unless the vector
33+
#' has only 1 element. If you wish to tag individual elements, you must use a
34+
#' list of 1-length vectors, each with a tag attribute. Likewise, if you set a
35+
#' tag for an object that would be emitted as a YAML mapping (like a data frame
36+
#' or a named list), it will be applied to the mapping as a whole. Tags can be
37+
#' used in conjunction with YAML deserialization functions like
38+
#' [yaml.load()] via custom handlers, however, if you set an internal
39+
#' tag on an incompatible data type (like \dQuote{!seq 1.0}), errors will occur
40+
#' when you try to deserialize the document.
41+
#'
42+
#' @param x The object to be converted.
43+
#' @param line.sep The line separator character(s) to use.
44+
#' @param indent The number of spaces to use for indenting.
45+
#' @param omap Determines whether or not to convert a list to a YAML omap; see
46+
#' Details.
47+
#' @param column.major Determines how to convert a data.frame; see Details.
48+
#' @param unicode Determines whether or not to allow unescaped unicode
49+
#' characters in output.
50+
#' @param precision Number of significant digits to use when formatting numeric
51+
#' values.
52+
#' @param indent.mapping.sequence Determines whether or not to indent sequences
53+
#' in mapping context.
54+
#' @param handlers Named list of custom handler functions for R objects; see
55+
#' Details.
56+
#' @return Returns a YAML string which can be loaded using
57+
#' [yaml.load()] or copied into a file for external use.
58+
#' @author Jeremy Stephens <jeremy.f.stephens@@vumc.org>
59+
#' @seealso [yaml.load()]
60+
#' @references YAML: http://yaml.org
61+
#'
62+
#' YAML omap type: http://yaml.org/type/omap.html
63+
#' @keywords data manip
64+
#' @export
65+
#' @examples
66+
#'
67+
#' as.yaml(1:10)
68+
#' as.yaml(list(foo=1:10, bar=c("test1", "test2")))
69+
#' as.yaml(list(foo=1:10, bar=c("test1", "test2")), indent=3)
70+
#' as.yaml(list(foo=1:10, bar=c("test1", "test2")), indent.mapping.sequence=TRUE)
71+
#' as.yaml(data.frame(a=1:10, b=letters[1:10], c=11:20))
72+
#' as.yaml(list(a=1:2, b=3:4), omap=TRUE)
73+
#' as.yaml("multi\nline\nstring")
74+
#' as.yaml(function(x) x + 1)
75+
#' as.yaml(list(foo=list(list(x = 1, y = 2), list(x = 3, y = 4))))
76+
#'
77+
#' # custom handler
78+
#' as.yaml(Sys.time(), handlers = list(
79+
#' POSIXct = function(x) format(x, "%Y-%m-%d")
80+
#' ))
81+
#'
82+
#' # custom handler with verbatim output to change how logical vectors are
83+
#' # emitted
84+
#' as.yaml(c(TRUE, FALSE), handlers = list(
85+
#' logical = verbatim_logical))
86+
#'
87+
#' # force quotes around a string
88+
#' port_def <- "80:80"
89+
#' attr(port_def, "quoted") <- TRUE
90+
#' x <- list(ports = list(port_def))
91+
#' as.yaml(x)
92+
#'
93+
#' # custom tag for scalar
94+
#' x <- "thing"
95+
#' attr(x, "tag") <- "!thing"
96+
#' as.yaml(x)
97+
#'
98+
#' # custom tag for sequence
99+
#' x <- 1:10
100+
#' attr(x, "tag") <- "!thing"
101+
#' as.yaml(x)
102+
#'
103+
#' # custom tag for mapping
104+
#' x <- data.frame(a = letters[1:5], b = letters[6:10])
105+
#' attr(x, "tag") <- "!thing"
106+
#' as.yaml(x)
107+
#'
108+
#' # custom tag for each element in a list
109+
#' x <- list(1, 2, 3)
110+
#' attr(x[[1]], "tag") <- "!a"
111+
#' attr(x[[2]], "tag") <- "!b"
112+
#' attr(x[[3]], "tag") <- "!c"
113+
#' as.yaml(x)
114+
#'
115+
as.yaml <- function(
116+
x,
117+
line.sep = c('\n', '\r\n', '\r'),
118+
indent = 2,
119+
omap = FALSE,
120+
column.major = TRUE,
121+
unicode = TRUE,
122+
precision = getOption('digits'),
123+
indent.mapping.sequence = FALSE,
124+
handlers = NULL
125+
) {
6126
line.sep <- match.arg(line.sep)
7-
res <- .Call(C_serialize_to_yaml, x, line.sep, indent, omap, column.major,
8-
unicode, precision, indent.mapping.sequence, handlers,
9-
PACKAGE="yaml")
127+
res <- .Call(
128+
C_serialize_to_yaml,
129+
x,
130+
line.sep,
131+
indent,
132+
omap,
133+
column.major,
134+
unicode,
135+
precision,
136+
indent.mapping.sequence,
137+
handlers,
138+
PACKAGE = "yaml"
139+
)
10140
Encoding(res) <- "UTF-8"
11141
res
12142
}

src/library/yaml/R/read_yaml.R

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,91 @@
1-
`read_yaml` <-
2-
function(file, fileEncoding = "UTF-8", text, error.label, readLines.warn=TRUE, ...) {
1+
#' Read a YAML file
2+
#'
3+
#' Read a YAML document from a file and create an R object from it
4+
#'
5+
#' This function is a convenient wrapper for [yaml.load()] and is a
6+
#' nicer alternative to [yaml.load_file()].
7+
#'
8+
#' You can specify a label to be prepended to error messages via the
9+
#' `error.label` argument. If `error.label` is missing,
10+
#' `read_yaml` will make an educated guess for the value of
11+
#' `error.label` by either using the specified filename (when `file`
12+
#' is a character vector) or using the description of the supplied connection
13+
#' object (via the `summary` function). If `text` is used, the
14+
#' default value of `error.label` will be `NULL`.
15+
#'
16+
#' @param file Either a character string naming a file or a [connection]
17+
#' open for reading.
18+
#' @param fileEncoding Character string: if non-empty declares the encoding
19+
#' used on a file (not a connection) so the character data can be re-encoded.
20+
#' See [file()].
21+
#' @param text Character string: if `file` is not supplied and this is,
22+
#' then data are read from the value of `text` via a text connection.
23+
#' Notice that a literal string can be used to include (small) data sets
24+
#' within R code.
25+
#' @param error.label A label to prepend to error messages (see Details).
26+
#' @param readLines.warn Logical (default: TRUE). Suppress warnings from
27+
#' readLines used inside read_yaml.
28+
#' @param ... Arguments to pass to [yaml.load()].
29+
#' @return If the root YAML object is a map, a named list or list with an
30+
#' attribute of 'keys' is returned. If the root object is a sequence, a list
31+
#' or vector is returned, depending on the contents of the sequence. A vector
32+
#' of length 1 is returned for single objects.
33+
#' @author Jeremy Stephens <jeremy.f.stephens@@vumc.org>
34+
#' @seealso [yaml.load()], [write_yaml()],
35+
#' [yaml.load_file()]
36+
#' @references YAML: http://yaml.org
37+
#'
38+
#' libyaml: https://pyyaml.org/wiki/LibYAML
39+
#' @keywords programming data manip
40+
#' @export
41+
#' @examples
42+
#'
43+
#' \dontrun{
44+
#' # reading from a file connection
45+
#' filename <- tempfile()
46+
#' cat("test: data\n", file = filename)
47+
#' con <- file(filename, "r")
48+
#' read_yaml(con)
49+
#' close(con)
50+
#'
51+
#' # using a filename to specify input file
52+
#' read_yaml(filename)
53+
#' }
54+
#'
55+
#' # reading from a character vector
56+
#' read_yaml(text="- hey\n- hi\n- hello")
57+
#'
58+
read_yaml <- function(
59+
file,
60+
fileEncoding = "UTF-8",
61+
text,
62+
error.label,
63+
readLines.warn = TRUE,
64+
...
65+
) {
366
if (missing(file) && !missing(text)) {
467
if (missing(error.label)) {
568
error.label <- NULL
669
}
770
file <- textConnection(text, encoding = "UTF-8")
871
on.exit(close(file))
9-
}
10-
else if (is.character(file)) {
72+
} else if (is.character(file)) {
1173
if (missing(error.label)) {
1274
error.label <- file
1375
}
14-
file <- if (nzchar(fileEncoding))
76+
file <- if (nzchar(fileEncoding)) {
1577
file(file, "rt", encoding = fileEncoding)
16-
else file(file, "rt")
78+
} else {
79+
file(file, "rt")
80+
}
1781
on.exit(close(file))
18-
}
19-
else if (inherits(file, "connection")) {
82+
} else if (inherits(file, "connection")) {
2083
if (missing(error.label)) {
2184
# try to guess filename
2285
s <- try(summary(file), silent = TRUE)
23-
if (!inherits(s, "try-error") && is.list(s) && "description" %in% names(s)) {
86+
if (
87+
!inherits(s, "try-error") && is.list(s) && "description" %in% names(s)
88+
) {
2489
error.label <- s$description
2590
}
2691
}
@@ -33,6 +98,6 @@ function(file, fileEncoding = "UTF-8", text, error.label, readLines.warn=TRUE, .
3398
stop("'file' must be a character string or connection")
3499
}
35100

36-
string <- paste(readLines(file,warn=readLines.warn), collapse="\n")
101+
string <- paste(readLines(file, warn = readLines.warn), collapse = "\n")
37102
yaml.load(string, error.label = error.label, ...)
38103
}

src/library/yaml/R/verbatim_logical.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
#' Alternative logical handler
2+
#'
3+
#' A yaml handler function that causes logical vectors to emit
4+
#' `true`/`false` instead of `yes`/`no` values.
5+
#'
6+
#' Pass this function to [`as.yaml()`][as.yaml] as part of the
7+
#' `handlers` argument list like `list(logical = verbatim_logical)`.
8+
#'
9+
#' @param x Logical vector to convert to `true`/`false`.
10+
#' @return Returns a vector of strings of either `true` or `false` of
11+
#' class `verbatim`.
12+
#' @author Charles Dupont and James Goldie (jimjam-slam)
13+
#' @seealso [as.yaml()]
14+
#' @keywords data manip
15+
#' @export
16+
#' @examples
17+
#'
18+
#' vector <- c(TRUE, FALSE, TRUE)
19+
#'
20+
#' as.yaml(vector, handlers=list(logical=verbatim_logical))
21+
#'
122
verbatim_logical <- function(x) {
223
result <- tolower(as.logical(x))
324
class(result) <- "verbatim"

0 commit comments

Comments
 (0)