Displaying 20 results from an estimated 147 matches for "vapply".
Did you mean:
apply
2015 Aug 03
2
'vapply' not returning list element names when returned element is a length-1 list
Hi all
Sorry for the confusing title. I noticed the following inconsistency:
If i have a function that returns a named list with 2 (or more) elements,
then using 'vapply' retains the names of the elements:
> vapply(1:3, function(x) list("foo" = "bar", "hello" = "world"),
> vector("list", 2))
[,1] [,2] [,3]
foo "bar" "bar" "bar"
hello "world" &qu...
2020 Jul 10
2
lapply and vapply Primitive Documentation
The documentation of ?lapply includes:
> lapply and vapply are primitive functions.
However, both evaluate to FALSE in `is.primitive()`:
is.primitive(vapply)
#FALSE
is.primitive(lapply)
#FALSE
It appears that they are not primitives and that the documentation
might be outdated. Thank you for your time and work.
Cole Miller
P.S. During...
2016 Feb 08
2
inconsistency in treatment of USE.NAMES argument
Hi,
Both vapply() and sapply() support the 'USE.NAMES' argument. According
to the man page:
USE.NAMES: logical; if ?TRUE? and if ?X? is character, use ?X? as
?names? for the result unless it had names already.
But if 'X' has names already and 'USE.NAMES' is FALSE, it's...
2014 Dec 17
2
vapply definition question
vapply <- function(X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE)
{
FUN <- match.fun(FUN)
if(!is.vector(X) || is.object(X)) X <- as.list(X)
.Internal(vapply(X, FUN, FUN.VALUE, USE.NAMES))
}
This is an implementor question. Basically, what happened to the '...'
args in the cal...
2014 Apr 12
1
vapply confusion
The following code seems to contain an inconsistency in
the behavior of vapply(). Am I missing something here?
## This function assumes v is a 3d vector, beta a scalar.
f3d <- function(v,beta) { v+beta }
## This expression applies f3d to a vector of scalars, and
## specifies the template 'array(10,3)' for the return value.
dat <- vapply(seq(0,1,length=10), fun...
2016 Feb 11
2
inconsistency in treatment of USE.NAMES argument
Changing the vapply() behavior makes sense in principle. I analyzed
the CRAN code base using the R parser and found 143 instances of
calling vapply with USE.NAMES=FALSE. These would need to be inspected
to understand the consequences of the change.
For reference:
/AzureML/R/datasets.R:226
/BBmisc/R/toRangeStr.R:33
/D...
2014 Dec 17
0
vapply definition question
On 12/16/2014 08:20 PM, Mick Jordan wrote:
> vapply <- function(X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE)
> {
> FUN <- match.fun(FUN)
> if(!is.vector(X) || is.object(X)) X <- as.list(X)
> .Internal(vapply(X, FUN, FUN.VALUE, USE.NAMES))
> }
>
> This is an implementor question. Basically, what happened to...
2015 Aug 05
0
'vapply' not returning list element names when returned element is a length-1 list
> -----Original Message-----
> From: R-devel [mailto:r-devel-bounces at r-project.org] On Behalf Of Dean Attali
> If i have a function that returns a named list with 2 (or more) elements,
> then using 'vapply' retains the names of the elements:
> ....
> But if the function only returns one element, then the name "foo" is lost
vapply _always simplifies_ according to the documentation.
In the first case (function return value contains more than one element, and each ), vapply simpli...
2015 Aug 06
0
'vapply' not returning list element names when returned element is a length-1 list
Quote----------------
> If i have a function that returns a named list with 2 (or more) elements,
> then using 'vapply' retains the names of the elements:
> ....
> But if the function only returns one element, then the name "foo" is lost
vapply _always simplifies_ according to the documentation.
In the first case (function return value contains more than one element, and each ), vapply simplif...
2016 Feb 09
0
inconsistency in treatment of USE.NAMES argument
>>>>> Herv? Pag?s <hpages at fredhutch.org>
>>>>> on Mon, 8 Feb 2016 10:48:50 -0800 writes:
> Hi,
> Both vapply() and sapply() support the 'USE.NAMES' argument. According
> to the man page:
> USE.NAMES: logical; if ?TRUE? and if ?X? is character, use ?X? as
> ?names? for the result unless it had names already.
> But if 'X' has names already and 'USE.NAMES&...
2012 Apr 19
2
Trouble with [sv]apply
Friends
I clearly donot understand how sapply and vapply work.
What I have is a function that returns a matrix with an indeterminate
number of rows (some times zero) but a constant number of columns. I
cannot reliably use an apply function to assemble the matrices into a
matrix. I am not sure it is possible.
I can demonstrate the core of my confusion...
2020 Jan 23
1
[External] Re: rpois(9, 1e10)
...eating most warnings as errors anyway) but for
the sake of other useRs who may get bitten, perhaps we should be more
explicit that backwards-compatibility won't be preserved under certain
use patterns, for example:
# works (with warning) in R 3.6.2 but fails (with error) in R-devel:
vapply(list(1e9, 1e10),
?????? function(lambda) {
????????? rpois(1L, lambda)
?????? },
?????? FUN.VALUE = integer(1L)
?????? )
# in R-devel, a little extra work to achieve a warning as before:
vapply(list(1e9, 1e10),
?????? function(lambda) {
????????? tmp <...
2019 Feb 19
4
code for sum function
...) s <- s + xi
s
}
kahanSum <- function (x)
{
s <- 0.0
c <- 0.0 # running compensation for lost low-order bits
for(xi in x) {
y <- xi - c
t <- s + y # low-order bits of y may be lost here
c <- (t - s) - y
s <- t
}
s
}
> rSum <- vapply(c(1:20,10^(2:7)), function(n) sum(rep(1/7,n)), 0)
> rNaiveSum <- vapply(c(1:20,10^(2:7)), function(n) naiveSum(rep(1/7,n)), 0)
> rKahanSum <- vapply(c(1:20,10^(2:7)), function(n) kahanSum(rep(1/7,n)), 0)
>
> table(rSum == rNaiveSum)
FALSE TRUE
21 5
> table(rSum == rKah...
2020 Nov 17
3
formatting issue with gcc 9.3.0 on Ubuntu on WSL2
...oblem - it gives the
same results for the fractional part as bc does.
bc: A2425FF7 5E14FC31 A125...
standalone: 22425FF7 5E14FC32
R: 22425FF7 5E151800
There are lots of other small numbers with the same problem:
> grep(value=TRUE, "0e",
vapply((1+(0:10000)/1000)*1e-15, deparse, ""))
[1] "8.56000000000000e-15" "8.71700000000000e-15" "8.77800000000000e-15"
[4] "8.93500000000000e-15" "9.50800000000000e-15" "9.83800000000000e-15"
[7] "9.89900000000000e-15" "...
2017 Mar 23
1
A question on stats::as.hclust.dendrogram
...R-devel, and this time I'm just asking for the purpose for a certain line of code in stats::as.hclust.dendrogram, which comes up as I'm trying to fix dendextend.
The line in question is at line 128 of dendrogram.R in R-3.3.3, at stats::as.hclust.dendrogram:
stopifnot(length(s) == 2L, all( vapply(s, is.integer, NA) ))
Is there any legitimate possibility that s is a nested list? Currently I have a case where a dendrogram object is breaks at this line, because s is a nested list:
>str (s)
List of 2
$ : int -779
$ :List of 2
..$ : int -625
..$ : int 15
I'm unsure if my dendrogram...
2024 Jun 13
1
Integration of functions with a vector argument
...t;mlevins at purdue.edu> ?????:
> f.int1 <- function(x,y) {Vectorize (function(y) f(c(x,y),H=H,j=j))}
Vectorize returns a callable function(y), so wrapping it in a
function(x,y) will not work. Since you'd like to integrate over y, we
can perform the same transformation manually using vapply:
# A version of f(...) that can be integrated over y
f.int1 <- function(y, x, H, j)
vapply(y, function(y) f(c(x,y), H = H, j = j), numeric(1))
The same transformation can be performed using Vectorize as follows:
f.int1 <- Vectorize(
function(y, x, H, j) f(c(x,y), H = H, j = j),
vectoriz...
2011 Aug 22
1
Data Frame Indexing
...01")
format(tm,"%a") %in% c("Sat","Sun")
}
use.lapply <- function(data) {
data[do.call(rbind,lapply(data$TIME,FUN=is.weekend)),]
}
use.sapply <- function(data) {
data[sapply(data$TIME,FUN=is.weekend),]
}
use.vapply <- function(data) {
data[vapply(data$TIME,FUN=is.weekend,FALSE),]
}
use.indexing <- function(data) {
data[is.weekend(data$TIME),]
}
And the results of these methods:
> names(csv.data)
[1] "TIME" "FILE" "RADIAN"...
2011 Oct 05
1
Vector-subsetting with ZERO - Is behavior changeable?
Dear All,
I have trouble generizising some code.
> index <- 0
> sapply(list(c(1,2,3),c(1,2),c(1)),function(x){x[max(length(x)-index,0)]})
Will yield a wished for vector like so:
[1] 3 2 1
But in this case (trying to select te second to last element in each vector
of the list)
> index <- 1
> sapply(list(c(1,2,3),c(1,2),c(1)),function(x){x[max(length(x)-index,0)]})
I end up
2023 Mar 02
3
tab-complete for non-syntactic names could attempt backtick-wrapping
There turn out to be a few more things to fix.
One problem is easy to solve: vapply() needs a third argument
specifying the type of the return value. (Can we have unit tests for
tab completion?)
The other problem is harder: `comps` defaults to an empty string, and
you can't have a symbol consisting of an empty string, because this
value is internally reserved for missing func...
2025 Jan 23
1
Depends: R (>= 4.1) for packages that use |> and \(...)
...call, but that feels quite fragile:
x <- utils::getParseData(parse(f, keep.source = TRUE))
i <- x$token %in% "PLACEHOLDER"
pi <- x[i, "parent"]
ppi <- x[x$id %in% pi, "parent"]
placeholder_expressions <- utils::getParseText(x, ppi)
extractor_used <- vapply(placeholder_expressions, function(src) {
toplevel <- parse(text = paste("PLACEHOLDER |> ", src))[[1]][[1]]
identical(toplevel, quote(`$`)) ||
identical(toplevel, quote(`[`)) ||
identical(toplevel, quote(`[[`))
}, FALSE)
Alternatively, we may find the first child of the grandp...