similar to: Assign and cmpfun

Displaying 20 results from an estimated 11000 matches similar to: "Assign and cmpfun"

2016 Dec 08
3
wish list: generalized apply
Dear All, I regularly want to "apply" some function to an array in a way that the arguments to the user function depend on the index on which the apply is working. A simple example is: A <- array( runif(160), dim=c(5,4,8) ) x <- matrix( runif(32), nrow=4, ncol=8 ) b <- runif(8) f1 <- function( A, x, b ) { sum( A %*% x ) + b } result <- rep(0.0,8) for (i in 1:8) {
2015 Sep 14
3
Optimization bug when byte compiling with gcc 5.2.0 on windows
When building R-devel with gcc 5.2.0 (mingw-w64 v4) on Windows, make check fails reg-tests-1b.R at the following check: x <- c(1:2, NA) sx <- sd(x) !is.nan(sx) Here 'sx' should be 'NA' but it is 'NaN'. It turns out this problem only appears when the function is byte compiled with optimization level 3: mysd <- function (x, na.rm = FALSE) sqrt(var(if
2019 Jan 03
2
Compiler + stopifnot bug
Hi, I found the following issue in r-devel (2019-01-02 r75945): `foo<-` <- function(x, value) { bar(x) <- value * x x } `bar<-` <- function(x, value) { stopifnot(all(value / x == 1)) x + value } `foo<-` <- compiler::cmpfun(`foo<-`) `bar<-` <- compiler::cmpfun(`bar<-`) x <- c(2, 2) foo(x) <- 1 x # should be c(4, 4) #> [1] 3 3 If the functions
2011 Jun 23
2
Loading List data into R with scan()
Hi All, I've been given a data file of the form: 1: 3,4,5,6 2:1,2,3 43: 5,7,8,9,5 and i want to read this data in as a list to create the form: (guessing final look) my.list [[1]] [1] 3 4 5 6 [[2]] [1] 1 2 3 [[43]] [1] 5 7 8 9 5 I can get to a stage using scan: scan("my.data", what = character(0), quiet = TRUE) to load [1] "1: 3,4,5,6" [2] "2:1,2,3" [3]
2019 Jan 04
2
Compiler + stopifnot bug
On 03/01/2019 3:37 p.m., Duncan Murdoch wrote: > I see this too; by bisection, it seems to have first appeared in r72943. Sorry, that was a typo. I meant r75943. Duncan Murdoch > > Duncan Murdoch > > On 03/01/2019 2:18 p.m., I?aki Ucar wrote: >> Hi, >> >> I found the following issue in r-devel (2019-01-02 r75945): >> >> `foo<-` <-
2005 Apr 27
1
RE: [R] when can we expect Prof Tierney's compiled R?
Luke, Thank you for sharing the benchmark results. The improvement is very substantial, I am looking forward to the release of the byte compiler! The arithmetic shows that x[i]<- is still the bottleneck. I suspect that this is due to a very involved dispatching/search for the appropriate function on the C level. There might be significant gain if loops somehow cached the result of the initial
2016 Nov 11
2
Frames in compiled functions
I noticed some problems that cropped in the latest versions of R-devel (2016-11-08 r71639 in my case) for one of my packages. I _think_ I have narrowed it down to the changes to what gets byte-compiled by default. The following example run illustrates the problem I'm having: compiler::enableJIT(0) fun <- function(x) local(as.list(parent.frame(2))) fun(1) ## $x ## [1] 1 ##
2019 Jan 04
2
Compiler + stopifnot bug
Thanks for the reports. Will look into it soon and report back. Luke Sent from my iPhone > On Jan 3, 2019, at 2:15 PM, Martin Morgan <mtmorgan.bioc at gmail.com> wrote: > > For what it's worth this also introduced > >> df = data.frame(v = package_version("1.2")) >> rbind(df, df)$v > [[1]] > [1] 1 2 > > [[2]] > [1] 1 2
2011 Dec 13
1
Rcpp too good to be true?
Hello all, I've been working on a package to do various things related to the Conway-Maxwell-Poisson distribution and wanted to be able to make fast random draws from the distribution. My R code was running quite slow so I decided to give Rcpp a bash. I had used it before but only for extremely basic stuff and always using inline. This time I decided to give making a proper package a go.
2010 Feb 25
3
behavior of seq_along
I'm trying to understand the behavior of seq_along in the following example: x <- 1:5; sum(x) y <- 6:10; sum(y) data <- c(x,y) S <- sum( data[seq_along(x)] ) S T <- sum( data[seq_along(y)] ) T Why is T != sum(y) ?
2017 Nov 22
2
function pointers?
We have a project that calls for the creation of a list of many distribution objects. Distributions can be of various types, with various parameters, but we ran into some problems. I started testing on a simple list of rnorm-based objects. I was a little surprised at the RAM storage requirements, here's an example: N <- 10000 closureList <- vector("list", N) nsize = sample(x
2007 Apr 03
1
Behavior of seq_along (was: Create a new var reflecting the order of subjects in existing var)
I am moving this from r-help to r-devel. Based on offline communications with Jim, suppose dat is defined as follows: set.seed(123) dat <- data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4), rep(5,5)), var1 =rnorm(17, 35,2), var2=runif(17,0,1)) # Then this ave call works as expected: ave(dat$ID, dat$ID, FUN = function(x) seq_along(x)) # but this apparently identical calculation
2009 Jul 09
1
bug in seq_along
Using the IRanges package from Bioconductor and somewhat recent R-2.9.1. ov = IRanges(1:3, 4:6) length(ov) # 3 seq(along = ov) # 1 2 3 as wanted seq_along(ov) # 1! I had expected that the last line would yield 1:3. My guess is that somehow seq_along don't utilize that ov is an S4 class with a length method. The last line of the *Details* section of ?seq has a typeo. Currently it is
2012 Nov 30
1
xts indexed with Date class
Hi I see a changed behaviour in xts indexed on class Date in the latest versions, versus 2. It seems to be related to changes to/from daylight savings time, happens those weekends. Is it not intended that class Date be used like this, or is this new behaviour incorrect? Giles Example: > a<-as.Date(15423:15426) > x<-xts(seq_along(a),a) > print(x) [,1] 2012-03-24
2012 Jan 06
1
seq_along and rep_along
Hi all, A couple of ideas for improving seq_along: * It would be really useful to have a second argument dim: seq_along(mtcars, 1) seq_along(mtcars, 2) # equivalent to seq_len(dim(mtcars)[1]) seq_len(dim(mtcars)[2]) I often find myself wanting to iterate over the rows or column of a data frame, and there isn't a particularly nice idiom if you want to avoid problems
2017 Jun 14
2
[WISH / PATCH] possibility to split string literals across multiple lines
Mark, that's actually a fair statement, although your extra operator doesn't cause construction at parse time. You still call paste0(), but just add an extra layer on top of it. I also doubt that even in gigantic loops the benefit is going to be significant. Take following example: atestfun <- function(x){ y <- paste0("a very long", "string for
2019 May 16
3
print.<strorageMode>() not called when autoprinting
In R-3.6.0 autoprinting was changed so that print methods for the storage modes are not called when there is no explicit class attribute. E.g., % R-3.6.0 --vanilla --quiet > print.function <- function(x, ...) { cat("Function with argument list "); cat(sep="\n ", head(deparse(args(x)), -1)); invisible(x) } > f <- function(x, ...) { sum( x * seq_along(x) ) }
2019 Mar 31
3
stopifnot
Ah, with R 3.5.0 or R 3.4.2, but not with R 3.3.1, 'eval' inside 'for' makes compiled version behave like non-compiled version. options(error = expression(NULL)) library(compiler) enableJIT(0) f <- function(x) for (i in 1) {x; eval(expression(i))} f(is.numeric(y)) # Error: object 'y' not found fc <- cmpfun(f) fc(is.numeric(y)) # Error: object 'y' not found
2009 Nov 22
2
Help with indexing
Dear R Helpers, I am missing something very elementary here, and I don't seem to get it from the help pages of the ave, seq and seq_along functions, so I wonder if you could offer a quick help. To use an example from an earlier post on this list, I have a dataframe of this kind: dat = data.frame(name = rep(c("Mary", "Sam", "John"), c(3,2,4))) dat$freq =
2012 Nov 20
2
correct function formation in R
Dear list! ? I have question of?'correct function formation'. Which function (fun1 or fun2; see below) is written more correctly? Using ''structure'' as output or creating empty ''data.frame'' and then transform it as output? (fun1 and fun1 is just for illustration). ? Thanks a lot, OV ? code: input <- data.frame(x1 = rnorm(20), x2 = rnorm(20), x3 =