diff --git a/doc/NEWS.Rd b/doc/NEWS.Rd index e4bdb3afe62..5bcb382086f 100644 --- a/doc/NEWS.Rd +++ b/doc/NEWS.Rd @@ -23,6 +23,10 @@ \item \code{confint.default()} now also works on S4 objects, as long as suitable \code{coef()} and \code{vcov()} methods exist. + \preformatted{ + obj <- new("MyS4Class") + confint(obj) + } \item \code{binomial(identity)} and \code{quasibinomial(identity)} now work without having to quote the argument. @@ -48,6 +52,10 @@ \samp{R >= 4.6.0}. \item \code{tools::analyze_license()} now also computes + \abbr{SPDX} license identifiers. Example usage: + \preformatted{ + tools::analyze_license("DESCRIPTION") + } \href{https://spdx.dev/learn/handling-license-info/}{\abbr{SPDX} license identifiers}, thanks to \I{Thierry Onkelinx} and \I{LLuís Revilla}. @@ -126,10 +134,12 @@ to allow literal pattern matching. Suggested and implemented by \I{Duncan Murdoch} in \PR{18925}. - \item \code{substring(txt, i1, i2)}, \code{substr(..)} and their - replacement versions now accept \code{i2 = NULL} to mean \dQuote{to - the end_of_string}, thus fulfilling \I{Kevin Ushey} (and others') - suggestions in \PR{18851}. + \item \code{substring(txt, i1, i2)} now accepts \code{i2 = NULL} + to mean "to the end of string". Example: + \preformatted{ + substring("Hello World", 7) # returns "World" + substring("Hello World", 7, NULL) # same result + } \item The default method for \code{pretty()} gets a new switch \code{bounds} for completeness, corresponding to \code{.pretty()}. Also, it now @@ -6679,5 +6689,5 @@ \ifelse{html}{\url{NEWS.3.html}}{\file{doc/html/NEWS.3.html}} and \ifelse{html}{\url{NEWS.2.html}}{\file{doc/html/NEWS.2.html}}. - } + }  } diff --git a/src/library/base/man/paste.Rd b/src/library/base/man/paste.Rd index 8ff68f6c80c..280d0c30af9 100644 --- a/src/library/base/man/paste.Rd +++ b/src/library/base/man/paste.Rd @@ -21,9 +21,10 @@ paste0(\dots, collapse = NULL, recycle0 = FALSE) the result is always a string (\code{\link{character}} of length 1).} \item{recycle0}{\code{\link{logical}} indicating if zero-length character arguments should result in the zero-length - \code{\link{character}(0)}. Note that when \code{collapse} is + \code{\link{character}(0)}. Note that when \code{collapse} is a string, \code{recycle0} does \emph{not} recycle to zero-length, but - to \code{""}.}% <== basic semantic of {collapse} mentioned above + to \code{""}. This ensures that a single character string is always + returned when \code{collapse} is specified.}% <== basic semantic of {collapse} mentioned above } \description{ Concatenate vectors after converting to character. @@ -46,7 +47,8 @@ paste0(\dots, collapse = NULL, recycle0 = FALSE) desirable, e.g.\sspace{}in \code{paste("the value of p is ", p)}. \code{paste0(\dots, collapse)} is equivalent to - \code{paste(\dots, sep = "", collapse)}, slightly more efficiently. + \code{paste(\dots, sep = "", collapse)}, slightly more efficiently + as it avoids handling a separator. If a value is specified for \code{collapse}, the values in the result are then concatenated into a single string, with the elements being diff --git a/src/library/base/man/substr.Rd b/src/library/base/man/substr.Rd index 973b19efb97..f9b4cd01b0e 100644 --- a/src/library/base/man/substr.Rd +++ b/src/library/base/man/substr.Rd @@ -58,6 +58,9 @@ substring(text, first, last = NULL) <- value If an input element has declared \code{"bytes"} encoding (see \code{\link{Encoding}}), the subsetting is done in units of bytes not characters. + When \code{start} or \code{stop} results in a zero-length extraction, an empty string + \code{""} is returned. Recycling is done to match the length of the longest input + vector, ensuring consistent behavior for vectorized operations. } \value{ For \code{substr}, a character vector of the same length and with the @@ -111,5 +114,9 @@ substring(x, 2) <- c("..", "+++") substring(X, 2) <- c("..", "+++") X stopifnot(x == X, identical(aX, attributes(X)), nzchar(comment(X))) + +## Demonstrating zero-length extraction behavior +substr(character(0), 1, 2) # returns character(0) +substring(c("abc", ""), 2) # returns "bc" and "" } \keyword{character}