Nonrandom character sequence with sample

Description

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

Usage

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

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

Value

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

Note

nameSample may take a lot of time, due to nchar^26 possibilities. That's why it warns about strings longer than 5 characters

Author(s)

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

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run in RCMD check as they're very time consuming
## Not run: 
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
                                       # on my slow laptop:   # on PC
system.time(nameSample("berr"))        # 25 s # berry: 57 s     10  23
system.time(nameSample("berr", FALSE)) # 23 s          53 s      9  20

# 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...


## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.