search for: rep_len

Displaying 20 results from an estimated 34 matches for "rep_len".

Did you mean: rem_len
2014 Mar 23
1
A rep_each function
...rsatility comes at a cost: it takes a bit of effort to learn (and remember) its syntax. This is a problem, since rep is one of the first functions many beginners will come across. Of the three main uses of rep, two have simpler alternatives. rep(x, times = ) has rep.int rep(x, length.out = ) has rep_len I think that a rep_each function would be a worthy addition for the third use case rep(x, each = ) (It might also be worth having rep_times as a synonym for rep.int.) While this could go in a package, since one of its main benefits is to help beginners, I feel it ought to go in base R. Before...
2014 Mar 26
2
R-devel Digest, Vol 133, Issue 23
...takes a bit of effort to learn (and remember) its syntax. > This is a problem, since rep is one of the first functions many > beginners will come across. Of the three main uses of rep, two have > simpler alternatives. > > rep(x, times = ) has rep.int > rep(x, length.out = ) has rep_len > > I think that a rep_each function would be a worthy addition for the > third use case > > rep(x, each = ) > > (It might also be worth having rep_times as a synonym for rep.int.) I think this is exactly the wrong approach. Indeed, the aim should be to get rid of function...
2016 Nov 29
0
ifelse() woes ... can we agree on a ifelse2() ?
...ical(test) n <- length(test) n.yes <- length(yes); n.no <- length(no) if (n.yes != n) { if (n.no == n) { # swap yes <-> no test <- !test ans <- yes; yes <- no; no <- ans n.no <- n.yes } else yes <- yes[rep_len(seq_len(n.yes), n)] } ans <- yes if (n.no == 1L) ans[!test] <- no else ans[!test & !is.na(test)] <- no[ if (n.no == n) !test & !is.na(test) else rep_len(seq_len(n.no), n)[!test & !is.na(test)]] stopifnot(length(NA.) ==...
2020 Jan 19
2
rpois(9, 1e10)
...???? I think that for, say, lambda>1e6, rpois should return rnorm(., lambda, sqrt(lambda)). ????? For my particular Monte Carlo, I have replaced my call to rpois with a call to the following: ?rpois. <- function(n, lambda){ ????? n2 <- max(length(n), length(lambda)) ????? n <- rep_len(n, n2) ????? lambda <- rep_len(lambda, n2) # ????? big <- (lambda>1e6) ????? out <- rep(NA, n2) ????? out[big] <- rnorm(sum(big), lambda[big], sqrt(lambda[big])) ????? out[!big] <- rpois(sum(!big), lambda[!big]) ????? out ? } ????? Comments? ????? Thanks, ????? Spencer...
2020 May 08
0
base::order making available retGrp and sortStr options for radix method?
..., method = "radix"). I was mildly aware that data.table ordering has made it into base R but I first thought the grouping feature of forder had been removed. However in fact it is there but disabled. base::order lines 31-35 reads: if (method == "radix") { decreasing <- rep_len(as.logical(decreasing), length(z)) return(.Internal(radixsort(na.last, decreasing, FALSE, TRUE, ...))) } which is essentially: return(.Internal(radixsort(na.last, decreasing, retGrp, sortStr, ...))) with the retGrp arguments which returns the group starts and the maximum grou...
2013 Dec 13
1
substring() and propagation of names
Hi, In R < 3.0.0, we used to get: > substring(c(A="abcdefghij", B="123456789"), 2, 6:2) A B A B A "bcdef" "2345" "bcd" "23" "b" But in R >= 3.0.0, we get: > substring(c(A="abcdefghij", B="123456789"), 2, 6:2) [1] "bcdef"
2020 Sep 08
2
Operations with long altrep vectors cause segfaults on Windows
I can only reproduce on Windows, but reliably (both 4.0.0 and 4.0.2): $> R --vanilla x <- c(0L, -2e9:2e9) # > Segmentation fault Tried to reproduce on Linux but the above worked as expected. Not an issue merely with the length of the vector; for example, x <- rep_len(1:10, 1e10) works, though the altrep vector must be long to reproduce: x <- c(0L, -1e9:1e9) #ok Segmentation faults occur with the following too: x <- (-2e9:2e9) + 1L
2019 Feb 20
2
Bug: time complexity of substring is quadratic as string size and number of substrings increases
...ps://github.com/tdhock/namedCapture-article/blob/master/figure-trackDb-pkgs.R I suspect that a fix can be accomplished by optimizing the implementation of substring, for the special case when the text/subject is a single element (character scalar). Right now I notice that the substring R code uses rep_len so that the text/subject which is passed to the C code is a character vector with the same length as the number of substrings to extract. Maybe the C code is calling strlen for each of these (identical) text/subject elements? Anyway, it would be useful to have some feedback to make sure this is in...
2018 May 03
1
Proposed speedup of ifelse
I propose a patch to ifelse that leverages anyNA(test) to achieve an improvement in performance. For a test vector of length 10, the change nearly halves the time taken and for a test of length 1 million, there is a tenfold increase in speed. Even for small vectors, the distributions of timings between the old and the proposed ifelse do not intersect. The patch does not intend to change the
2023 Feb 23
1
Palettes {grDevices} - wrong number of colors returned?
...lpha = alpha)) if(rev) rev(cols) else cols } else character() } A bug fix would be to recycle alpha to the right length and only pass in portions of it, e.g. terrain.colors <- function (n, alpha, rev = FALSE) { if ((n <- as.integer(n[1L])) > 0) { alpha <- rep_len(alpha, length.out = n) k <- n%/%2 h <- c(4/12, 2/12, 0/12) s <- c(1, 1, 0) v <- c(0.65, 0.9, 0.95) cols <- c(hsv(h = seq.int(h[1L], h[2L], length.out = k), s = seq.int(s[1L], s[2L], length.out = k), v = seq.int(v[1L], v[2L], length.o...
2023 Feb 23
2
Palettes {grDevices} - wrong number of colors returned?
Hi, I would have expected that I get always 3 colors as result which is not true: hcl.colors(3, alpha=c(0, 0.5, 1)) # 3 colors rainbow(3, alpha=c(0, 0.5, 1)) # 3 colors heat.colors(3, alpha=c(0, 0.5, 1)) # 3 colors terrain.colors(3, alpha=c(0, 0.5, 1)) # 6 colors cm.colors(3, alpha=c(0, 0.5, 1)) # 6 colors topo.colors(3, alpha=c(0, 0.5, 1)) # 9 colors R-Version and
2020 Sep 08
4
Operations with long altrep vectors cause segfaults on Windows
....0.0 and 4.0.2): >> $> R --vanilla >> x <- c(0L, -2e9:2e9) >> # > Segmentation fault >> Tried to reproduce on Linux but the above worked as expected. Not an >> issue merely with the length of the vector; for example, x <- >> rep_len(1:10, 1e10) works, though the altrep vector must be long to >> reproduce: >> x <- c(0L, -1e9:1e9) #ok >> Segmentation faults occur with the following too: >> x <- (-2e9:2e9) + 1L > Your operation would "need" (not in theory, but in...
2019 Feb 22
1
Bug: time complexity of substring is quadratic as string size and number of substrings increases
...blob/master/figure-trackDb-pkgs.R >> >> I suspect that a fix can be accomplished by optimizing the implementation >> of substring, for the special case when the text/subject is a single >> element (character scalar). Right now I notice that the substring R code >> uses rep_len so that the text/subject which is passed to the C code is a >> character vector with the same length as the number of substrings to >> extract. Maybe the C code is calling strlen for each of these (identical) >> text/subject elements? >> >> Anyway, it would be useful t...
2020 Sep 08
2
[External] Re: Operations with long altrep vectors cause segfaults on Windows
...; >> x <- c(0L, -2e9:2e9) >> >> >> # > Segmentation fault >> >> >> Tried to reproduce on Linux but the above worked as expected. Not an >> >> issue merely with the length of the vector; for example, x <- >> >> rep_len(1:10, 1e10) works, though the altrep vector must be long to >> >> reproduce: >> >> >> x <- c(0L, -1e9:1e9) #ok >> >> >> Segmentation faults occur with the following too: >> >> >> x <- (-2e9:2e9) + 1L >> >&...
2020 Sep 08
1
[External] Re: Operations with long altrep vectors cause segfaults on Windows
...x <- c(0L, -2e9:2e9) >> >> >> # > Segmentation fault >> >> >> Tried to reproduce on Linux but the above worked as expected. Not an >> >> issue merely with the length of the vector; for example, x <- >> >> rep_len(1:10, 1e10) works, though the altrep vector must be long to >> >> reproduce: >> >> >> x <- c(0L, -1e9:1e9) #ok >> >> >> Segmentation faults occur with the following too: >> >> >> x <- (-2e9:2e9)...
2024 Jan 29
1
strcapture performance when perl = TRUE
...X...1 1 Ben Franklin 2 Millard Fillmore 3 <NA> <NA> 4 <NA> <NA> Now to compare timings over multiple reps: lengths <- sort(outer(c(1, 2, 5), 10^(1:4))) reps <- 20 time_strcapture <- function(text, length, regex, proto, reps) { text <- rep_len(text, length) str <- system.time(for (i in seq_len(reps)) strcapture(regex, text, proto, perl = TRUE)) str2 <- system.time(for (i in seq_len(reps)) strcapture2(regex, text, proto, perl = TRUE)) c(strcapture = str[["user.self"]], strcapture2 = str2[["user.self"]...
2019 Feb 20
0
Bug: time complexity of substring is quadratic as string size and number of substrings increases
...amedCapture-article/blob/master/figure-trackDb-pkgs.R > > I suspect that a fix can be accomplished by optimizing the implementation > of substring, for the special case when the text/subject is a single > element (character scalar). Right now I notice that the substring R code > uses rep_len so that the text/subject which is passed to the C code is a > character vector with the same length as the number of substrings to > extract. Maybe the C code is calling strlen for each of these (identical) > text/subject elements? > > Anyway, it would be useful to have some feedback...
2020 Sep 08
0
Operations with long altrep vectors cause segfaults on Windows
...ws, but reliably (both 4.0.0 and 4.0.2): > $> R --vanilla > x <- c(0L, -2e9:2e9) > # > Segmentation fault > Tried to reproduce on Linux but the above worked as expected. Not an > issue merely with the length of the vector; for example, x <- > rep_len(1:10, 1e10) works, though the altrep vector must be long to > reproduce: > x <- c(0L, -1e9:1e9) #ok > Segmentation faults occur with the following too: > x <- (-2e9:2e9) + 1L Your operation would "need" (not in theory, but in practice) to go from alt...
2023 Feb 23
1
Palettes {grDevices} - wrong number of colors returned?
...cols > } else character() > } > > > A bug fix would be to recycle alpha to the right length and only pass in > portions of it, e.g. > > terrain.colors <- function (n, alpha, rev = FALSE) > { > if ((n <- as.integer(n[1L])) > 0) { > alpha <- rep_len(alpha, length.out = n) > k <- n%/%2 > h <- c(4/12, 2/12, 0/12) > s <- c(1, 1, 0) > v <- c(0.65, 0.9, 0.95) > cols <- c(hsv(h = seq.int(h[1L], h[2L], length.out = k), > s = seq.int(s[1L], s[2L], length.out = k), > v =...
2016 Nov 26
3
ifelse() woes ... can we agree on a ifelse2() ?
...ical(test) ? ? n <- length(test) ? ? n.yes <- length(yes); n.no <- length(no) ? ? if (n.yes != n) { ? ? ? ? if (n.no == n) {? # swap yes <-> no ? ? ? ? ? ? test <- !test ? ? ? ? ? ? ans <- yes; yes <- no; no <- ans ? ? ? ? ? ? n.no <- n.yes ? ? ? ? } else yes <- yes[rep_len(seq_len(n.yes), n)] ? ? } ? ? ans <- yes ? ? if (n.no == 1L) ? ? ? ? ans[!test] <- no ? ? else ? ? ? ? ans[!test & !is.na(test)] <- no[ ? ? ? ? ? ? if (n.no == n) !test & !is.na(test) ? ? ? ? ? ? else rep_len(seq_len(n.no), n)[!test & !is.na(test)]] ? ? stopifnot(length(NA.) ==...