Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BZ-18658] Fixes to examples running with only base attached #153

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library/base/man/Quotes.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ writeLines(x) # see also ?strwrap
## non-standard.)
`x y` <- 1:5
`x y`
d <- data.frame(`1st column` = rchisq(5, 2), check.names = FALSE)
d <- data.frame(`1st column` = stats::rchisq(5, 2), check.names = FALSE)
d$`1st column`

## Backslashes followed by up to three numbers are interpreted as
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/Sys.getenv.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Sys.getenv(c("R_HOME", "R_PAPERSIZE", "R_PRINTCMD", "HOST"))
s <- Sys.getenv() # *all* environment variables
op <- options(width=111) # (nice printing)
names(s) # all settings (the values could be very long)
head(s, 12) # using the Dlist print() method
utils::head(s, 12) # using the Dlist print() method

## Language and Locale settings -- but rather use Sys.getlocale()
s[grep("^L(C|ANG)", names(s))]
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/Trig.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ x <- seq(-3, 7, by = 1/8)
tx <- cbind(x, cos(pi*x), cospi(x), sin(pi*x), sinpi(x),
tan(pi*x), tanpi(x), deparse.level=2)
op <- options(digits = 4, width = 90) # for nice formatting
head(tx)
utils::head(tx)
tx[ (x \%\% 1) \%in\% c(0, 0.5) ,]
options(op)
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/as.POSIXlt.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ as.POSIXct(strptime("2010-10-31 01:30:00", "\%Y-\%m-\%d \%H:\%M:\%S"))
unclass(z) # a large integer
floor(unclass(z)/86400) # the number of days since 1970-01-01 (UTC)
(now <- as.POSIXlt(Sys.time())) # the current datetime, as class "POSIXlt"
str(unclass(now)) # the internal list ; use now$hour, etc :
utils::str(unclass(now)) # the internal list ; use now$hour, etc :
now$year + 1900 # see ?DateTimeClasses
months(now); weekdays(now) # see ?months; using LC_TIME locale

Expand Down
6 changes: 3 additions & 3 deletions src/library/base/man/balancePOSIXlt.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ Sys.setenv(TZ = "UTC")
d1 <- as.POSIXlt("2000-01-02 3:45")
d1$min <- d1$min + (0:16)*20L
(f1 <- format(d1))
str(unclass(d1)) # only $min is of length > 1
utils::str(unclass(d1)) # only $min is of length > 1
df <- balancePOSIXlt(d1, fill.only = TRUE) # a "POSIXlt" object
str(unclass(df)) # all of length 17; 'min' unchanged
utils::str(unclass(df)) # all of length 17; 'min' unchanged
db <- balancePOSIXlt(d1, classed = FALSE) # a list
stopifnot(identical(
unCfillPOSIXlt(d1),
balancePOSIXlt(d1, fill.only = TRUE, classed = FALSE)))
str(db) # of length 17 *and* in range
utils::str(db) # of length 17 *and* in range
\dontshow{
stopifnot(exprs = {
identical(f1, format(df))
Expand Down
6 changes: 4 additions & 2 deletions src/library/base/man/call.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ g
eval(g)

## Special calls (and some regular ones):
L <- as.list(E <- setNames( , c("if", "for", "while", "repeat", "function",
"(", "{", "[", "<-", "<<-", "->", "=")))
E <- c("if", "for", "while", "repeat", "function",
"(", "{", "[", "<-", "<<-", "->", "=")
names(E) <- E
L <- as.list(E)
for(i in seq_along(L)) L[[i]] <- call(E[[i]]) # instead of lapply(E, call) ..
list_ <- function (...) `names<-`(list(...), vapply(sys.call()[-1L], as.character, ""))
(Tab <- noquote(sapply(list_(is.call, typeof, class, mode), \(F) sapply(L, F))))
Expand Down
4 changes: 2 additions & 2 deletions src/library/base/man/cbind.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ rbind(1:4, c = 2, "a++" = 10, dd, deparse.level = 1) # 3 rownames (default)
rbind(1:4, c = 2, "a++" = 10, dd, deparse.level = 2) # 4 rownames

## cheap row names:
b0 <- gl(3,4, labels=letters[1:3])
bf <- setNames(b0, paste0("o", seq_along(b0)))
b0 <- bf <- gl(3,4, labels=letters[1:3])
names(bf) <- paste0("o", seq_along(b0))
df <- data.frame(a = 1, B = b0, f = gl(4,3))
df. <- data.frame(a = 1, B = bf, f = gl(4,3))
new <- data.frame(a = 8, B ="B", f = "1")
Expand Down
1 change: 1 addition & 0 deletions src/library/base/man/chkDots.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ seq.default ## <- you will see ' chkDots(...) '
seq(1,5, foo = "bar") # gives warning via chkDots()

## warning with more than one ...-entry:
require(stats)
density.f <- function(x, ...) NextMethod("density")
x <- density(structure(rnorm(10), class="f"), bar=TRUE, baz=TRUE)
}
Expand Down
4 changes: 2 additions & 2 deletions src/library/base/man/cut.POSIXt.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ cut(as.Date("2001/1/1") + 70*stats::runif(100), "weeks")
# The standards all have midnight as the start of the day, but some
# people incorrectly interpret it at the end of the previous day ...
tm <- seq(as.POSIXct("2012-06-01 06:00"), by = "6 hours", length.out = 24)
aggregate(1:24, list(day = cut(tm, "days")), mean)
stats::aggregate(1:24, list(day = cut(tm, "days")), mean)
# and a version with midnight included in the previous day:
aggregate(1:24, list(day = cut(tm, "days", right = TRUE)), mean)
stats::aggregate(1:24, list(day = cut(tm, "days", right = TRUE)), mean)
}
\keyword{manip}
\keyword{chron}
4 changes: 2 additions & 2 deletions src/library/base/man/dimnames.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ colnames0 <- function(x) dimnames(x)[[2]]
A0 <- A; dimnames(A)[2:3] <- list(NULL)
stopifnot(identical(A0, provideDimnames(A)))
strd <- function(x) utils::str(dimnames(x))
strd(provideDimnames(A, base= list(letters[-(1:9)], tail(LETTERS))))
strd(provideDimnames(N, base= list(letters[-(1:9)], tail(LETTERS)))) # recycling
strd(provideDimnames(A, base= list(letters[-(1:9)], utils::tail(LETTERS))))
strd(provideDimnames(N, base= list(letters[-(1:9)], utils::tail(LETTERS)))) # recycling
strd(provideDimnames(A, base= list(c("AA","BB")))) # recycling on both levels
## set "empty dimnames":
provideDimnames(rbind(1, 2:3), base = list(""), unique=FALSE)
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/dput.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ dget(fil) - xx # slight rounding on some platforms
dput(xx, fil, control = "hexNumeric"); dget(fil) - xx
unlink(fil)

xn <- setNames(xx, paste0("pi^",1:3))
xn <- stats::setNames(xx, paste0("pi^",1:3))
dput(xn) # nicer, now "niceNames" being part of default 'control'
dput(xn, control = "S_compat") # no names
## explicitly asking for output as in R < 3.5.0:
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/formals.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ names(formals(lm))
methods:: formalArgs(lm) # same

## formals returns a pairlist. Arguments with no default have type symbol (aka name).
str(formals(lm))
utils::str(formals(lm))

## formals returns NULL for primitive functions. Use it in combination with
## args for this case.
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/format.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ format(2^31-1)
format(2^31-1, scientific = TRUE)
## scientific = numeric scipen (= {sci}entific notation {pen}alty) :
x <- c(1e5, 1000, 10, 0.1, .001, .123)
t(sapply(setNames(,-4:1),
t(sapply(stats::setNames(,-4:1),
\(sci) sapply(x, format, scientific=sci)))


Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/formatc.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ stopifnot(pnv == "1+1i", pnv == format(zv),
pnv == prettyNum(zv, drop0trailing = TRUE))
## more digits change the picture:
options(digits = 8)
head(fv <- format(zv), 3)
utils::head(fv <- format(zv), 3)
prettyNum(fv)
prettyNum(fv, drop0trailing = TRUE) # a bit nicer
options(op)
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/gzcon.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ z <- gzcon(url("https://www.stats.ox.ac.uk/pub/datasets/csb/ch12.dat.gz"))
# read.table can only read from a text-mode connection.
raw <- textConnection(readLines(z))
close(z)
dat <- read.table(raw)
dat <- utils::read.table(raw)
close(raw)
dat[1:4, ]
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/iconv.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ try(iconv(x, "latin1", "ASCII//TRANSLIT")) # platform-dependent
iconv(x, "latin1", "ASCII", sub = "byte")

## and for Windows' 'Unicode'
str(xx <- iconv(x, "latin1", "UTF-16LE", toRaw = TRUE))
utils::str(xx <- iconv(x, "latin1", "UTF-16LE", toRaw = TRUE))
iconv(xx, "UTF-16LE", "UTF-8")

emoji <- "\U0001f604"
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/identical.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ identical(f, g) # TRUE, as bytecode is ignored by default
identical(f, g, ignore.bytecode=FALSE) # FALSE: bytecode differs

## GLM families contain several functions, some of which share an environment:
p1 <- poisson() ; p2 <- poisson()
p1 <- stats::poisson() ; p2 <- stats::poisson()
identical(p1, p2) # FALSE
identical(p1, p2, ignore.environment=TRUE) # TRUE

Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/ifelse.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ifelse(x >= 0, sqrt(x), NA)
x <- seq(as.Date("2000-02-29"), as.Date("2004-10-04"), by = "1 month")
## has many "yyyy-mm-29", but a few "yyyy-03-01" in the non-leap years
y <- ifelse(as.POSIXlt(x)$mday == 29, x, NA)
head(y) # not what you expected ... ==> need restore the class attribute:
utils::head(y) # not what you expected ... ==> need restore the class attribute:
class(y) <- class(x)
y
## This is a (not atypical) case where it is better *not* to use ifelse(),
Expand Down
1 change: 1 addition & 0 deletions src/library/base/man/library.dynam.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ library.dynam()

## More on library.dynam.unload() :
\donttest{require(nlme)
require(utils)
nlme:::.onUnload # shows library.dynam.unload() call
detach("package:nlme") # by default, unload=FALSE , so,
tail(library.dynam(), 2)# nlme still there
Expand Down
3 changes: 2 additions & 1 deletion src/library/base/man/list2env.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ stopifnot(identical(L [sort.list(names(L ))],

## now add to e -- can be seen as a fast "multi-assign":
list2env(list(abc = LETTERS, note = "just an example",
df = data.frame(x = rnorm(20), y = rbinom(20, 1, prob = 0.2))),
df = data.frame(x = stats::rnorm(20),
y = stats::rbinom(20, 1, prob = 0.2))),
envir = e)
utils::ls.str(e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/locales.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Sys.setenv("LANGUAGE" = "es") # set the language for error/warning messages
##' show a "full" Sys.getlocale() nicely:
showL <- function(loc) {
sl <- strsplit(strsplit(loc, sep)[[1L]], "=")
setNames(sapply(sl, `[[`, 2L), sapply(sl, `[[`, 1L))
stats::setNames(sapply(sl, `[[`, 2L), sapply(sl, `[[`, 1L))
}
print.Dlist(lloc <- showL(Sys.getlocale()))
## R-supported ones (but LC_ALL):
Expand Down
4 changes: 2 additions & 2 deletions src/library/base/man/match.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ unique(zN) # the "NA" and the 3 different non-NA NaN's
stopifnot(identical(unique(zN), zN[c(1, 7,9,10)]))

## very strict equality would have 4 duplicates (of 12):
symnum(outer(zN, zN, Vectorize(identical,c("x","y")),
FALSE,FALSE,FALSE,FALSE))
stats::symnum(outer(zN, zN, Vectorize(identical,c("x","y")),
FALSE,FALSE,FALSE,FALSE))
## removing "(very strictly) duplicates",
i <- c(5,8,11,12) # we get 8 pairwise non-identicals :
Ixy <- outer(zN[-i], zN[-i], Vectorize(identical,c("x","y")),
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/nchar.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ nchar(deparse(mean))
# 18 17 <-- unless mean differs from base::mean

## NA behaviour as function of keepNA=* :
logi <- setNames(, c(FALSE, NA, TRUE))
logi <- stats::setNames(, c(FALSE, NA, TRUE))
sapply(logi, \(k) data.frame(nchar = nchar (NA, keepNA=k),
nzchar = nzchar(NA, keepNA=k)))

Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/parse.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ an error
"
sf <- srcfile("txt")
tryCatch(parse(text = txt, srcfile = sf), error = function(e) "Syntax error.")
getParseData(sf)
utils::getParseData(sf)
}
\keyword{file}
\keyword{programming}
Expand Down
5 changes: 3 additions & 2 deletions src/library/base/man/pipeOp.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
}
\examples{
# simple uses:
mtcars |> head() # same as head(mtcars)
mtcars |> head(2) # same as head(mtcars, 2)
require(utils)
mtcars |> head() # same as head(mtcars)
mtcars |> head(2) # same as head(mtcars, 2)
mtcars |> subset(cyl == 4) |> nrow() # same as nrow(subset(mtcars, cyl == 4))

# to pass the lhs into an argument other than the first, either
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/proc.time.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ proc.time()
\examples{\donttest{
## a way to time an R expression: system.time is preferred
ptm <- proc.time()
for (i in 1:50) mad(stats::runif(500))
for (i in 1:50) stats::mad(stats::runif(500))
proc.time() - ptm
}}
\keyword{utilities}
4 changes: 2 additions & 2 deletions src/library/base/man/qr.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ h9 \%*\% x # = y


## overdetermined system
A <- matrix(runif(12), 4)
A <- matrix(stats::runif(12), 4)
b <- 1:4
qr.solve(A, b) # or solve(qr(A), b)
solve(qr(A, LAPACK = TRUE), b)
# this is a least-squares solution, cf. lm(b ~ 0 + A)

## underdetermined system
A <- matrix(runif(12), 3)
A <- matrix(stats::runif(12), 3)
b <- 1:3
qr.solve(A, b)
solve(qr(A, LAPACK = TRUE), b)
Expand Down
3 changes: 2 additions & 1 deletion src/library/base/man/rawConversion.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ stopifnot(exprs = {
identical(packBits( 0:31) ,
packBits(as.raw(0:31)))
})
require(utils)
str(pBi <- packBits(intToBits(i)))
data.frame(B = matrix(pBi, nrow=6, byrow=TRUE),
hex = format(as.hexmode(i)), i)
Expand Down Expand Up @@ -147,7 +148,7 @@ bitC(1+2^-(1:53))# from 0.5 converge to 1
d2bI <- function(x) vapply(as.double(x), function(x) intToBits(numToInts(x)), raw(64L))
d2b <- function(x) vapply(as.double(x), function(x) numToBits(x) , raw(64L))
set.seed(1)
x <- c(sort(rt(2048, df=1.5)), 2^(-10:10), 1+2^-(1:53))
x <- c(sort(stats::rt(2048, df=1.5)), 2^(-10:10), 1+2^-(1:53))
str(bx <- d2b(x)) # a 64 x 2122 raw matrix
stopifnot( identical(bx, d2bI(x)) )

Expand Down
3 changes: 2 additions & 1 deletion src/library/base/man/regmatches.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ z

## With `perl = TRUE` and `invert = FALSE` capture group names
## are preserved. Collect functions and arguments in calls:
require(utils)
NEWS <- head(readLines(file.path(R.home(), 'doc', 'NEWS.2')), 100)
m <- gregexec("(?<fun>\\\\w+)\\\\((?<args>[^)]*)\\\\)", NEWS, perl = TRUE)
y <- regmatches(NEWS, m)
y[[16]]
## Make tabular, adding original line numbers
mdat <- as.data.frame(t(do.call(cbind, y)))
mdat <- cbind(mdat, line=rep(seq_along(y), lengths(y) / ncol(mdat)))
head(mdat)
utils::head(mdat)
NEWS[head(mdat[['line']])]
}
\keyword{character}
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/substr.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ substring(x, 2, 4:6)
X <- x
names(X) <- LETTERS[seq_along(x)]
comment(X) <- noquote("is a named vector")
str(aX <- attributes(X))
utils::str(aX <- attributes(X))
substring(x, 2) <- c("..", "+++")
substring(X, 2) <- c("..", "+++")
X
Expand Down
1 change: 1 addition & 0 deletions src/library/base/man/textconnections.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
weight <- c(ctl, trt)
sink(zz)
require(stats)
anova(lm.D9 <- lm(weight ~ group))
cat("\nSummary of Residuals:\n\n")
summary(resid(lm.D9))
Expand Down
1 change: 1 addition & 0 deletions src/library/base/man/timezones.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ OlsonNames(tzdir = NULL)
}

\examples{
require(utils)
Sys.timezone()

str(OlsonNames()) ## typically around six hundred names,
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/trace.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ require(stats)

## Very simple use
trace(sum)
hist(rnorm(100)) # shows about 3-4 calls to sum()
graphics::hist(rnorm(100)) # shows about 3-4 calls to sum()
untrace(sum)

## Show how pt() is called from inside power.t.test():
Expand Down
2 changes: 1 addition & 1 deletion src/library/base/man/warnings.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ for(w in -1:1) {
}
## at the end prints all three warnings, from the 'option(warn = 0)' above
options(ow) # reset to previous, typically 'warn = 0'
tail(warnings(), 2) # see the last two warnings only (via '[' method)
utils::tail(warnings(), 2) # see the last two warnings only (via '[' method)

## Often the most useful way to look at many warnings:
summary(warnings())
Expand Down
Loading