Learn R Programming

berryFunctions (version 1.22.5)

nameSample: Nonrandom character sequence with sample

Description

Find the seed necessary to produce a character sequence by using sample

Usage

nameSample(name, progress = FALSE, estimatetime = nc > 4, continue = FALSE)

Value

cats command into the console that can be copypasted to anyone's R script.

Arguments

name

Character string. long strings (>>5) will compute a VERY long time!

progress

Logical. Monitor progress by printing a dot every 10000 tries? DEFAULT: TRUE for long names (nchar(name)>3).

estimatetime

Estimate computation time? DEFAULT: nc>4

continue

Continue without asking? DEFAULT: FALSE

Author

Berry Boessenkool, berry-b@gmx.de, April 2014

See Also

yearSample to wish a happy new year, set.seed, sample, letters

Examples

Run this code

## Not run in RCMD check as they're very time consuming
if (FALSE) {
# nameSample("berry")  # After that, you can send the result to colleagues:
# Kind regards from
set.seed(1248272); paste(sample(letters,5,TRUE), collapse='')

# calculation time

system.time(nameSample("ber"))
system.time(nameSample("ber", FALSE))

# let <- sapply(1:4, function(n) apply(replicate(n, letters[sample(15)]), 1, paste, collapse=""))
# calctime <- sapply(let, function(x) system.time(nameSample(x, progress=F))[3])
# write.table(calctime, "calctime_nameSample.txt")
ctfile  <- system.file("extdata/calctime_nameSample.txt",  package="berryFunctions")
ctfile2 <- system.file("extdata/calctime_nameSample2.txt", package="berryFunctions")
calctime <- read.table(ctfile)
# regression result in hours:
expReg(nchar(rownames(calctime))-8, calctime[,1], xlim=c(1,7), ylim=c(-3,4),
       predict=7)/3600

# For my 3 times faster computer:
calctime <- read.table(ctfile2)
expReg(nchar(rownames(calctime))-8, calctime[,1], xlim=c(1,7), ylim=c(-3,4),
       predict=c(4,7))/c(1,3600)
# 4 sec for 4 letters are expected to be 10 hours for 7 letters...

}

Run the code above in your browser using DataLab