Re: [Rd] findInterval

2024-09-17 Thread Gabor Grothendieck
s the base of R now has pipes. On Tue, Sep 17, 2024 at 12:14 PM Martin Maechler wrote: > > >>>>> Gabor Grothendieck > >>>>> on Mon, 16 Sep 2024 11:21:55 -0400 writes: > > > Suppose we have `dat` shown below and we want to find the the `y` val

[Rd] findInterval

2024-09-16 Thread Gabor Grothendieck
Suppose we have `dat` shown below and we want to find the the `y` value corresponding to the last value in `x` equal to the corresponding component of `seek` and we wish to return an output the same length as `seek` using `findInterval` to perform the search. This returns the correct result: d

Re: [Rd] transform

2024-09-08 Thread Gabor Grothendieck
reas (the wisdom of this escapes me) > > > >> data.frame(head(airquality), y=data.frame(x=rnorm(6),z=rnorm(6))) > >Ozone Solar.R Wind Temp Month Dayy.x y.z > > 141 190 7.4 67 5 1 -0.9250228 0.46483406 > > 236 118 8.0

Re: [Rd] Inconsistency between row and nrow

2024-09-08 Thread Gabor Grothendieck
when x is a matrix." > > further differentiating the behavior of row() and col() as more specific > implementations in the 2-dimensional case. > > To my read then, the difference in behavior appears to be intentional and > expected. > > Regards, > > Marc Schwart

[Rd] Inconsistency between row and nrow

2024-09-08 Thread Gabor Grothendieck
In the following nrow provides the expected result but row gives an error. I would have thought that they would both work or both fail. aa <- array(dim = 5:3) nrow(aa) ## [1] 5 row(aa) ## Error in row(aa) : a matrix-like object is required as argument to 'row' # this does work: s

Re: [Rd] transform

2024-08-27 Thread Gabor Grothendieck
.z > 141 190 7.4 67 5 1 -0.9250228 0.46483406 > 236 118 8.0 72 5 2 -0.5035793 0.28822668 > ... > > On the whole, I think that transform was never designed (nor documented) to > take data frame arguments, so caveat emptor. > > - Peter >

[Rd] transform

2024-08-24 Thread Gabor Grothendieck
One oddity in transform that I recently noticed. It seems that to include a one-column data frame in the arguments one must name it even though the name is ignored. If the data frame has more than one column then it must also be named but in that case it is not ignored and the names are made up o

Re: [Rd] head.ts, tail.ts loses time

2024-06-11 Thread Gabor Grothendieck
ies > > I think I'd consider using windows() for a head.ts() and tail.ts(), > but in any case, I am sympathetic adding such methods to "base R"'s > utils package. > > > Martin > > > Best Wishes, Spencer Graves > > >

Re: [Rd] head.ts, tail.ts loses time

2024-06-09 Thread Gabor Grothendieck
zoo overcomes many of the limitations of ts: library(zoo) as.ts(head(as.zoo(presidents))) ## Qtr1 Qtr2 Qtr3 Qtr4 ## 1945 NA 87 82 75 ## 1946 63 50 xts also works here. On Sun, Jun 9, 2024 at 12:04 PM Spencer Graves wrote: > > Hello, All: > > > The 'head' and

Re: [Rd] capture "->"

2024-03-02 Thread Gabor Grothendieck
Would it be good enough to pass it as a formula? Using your definition of foo foo(~ A -> result) ## result <- ~A foo(~ result <- A) ## ~result <- A On Fri, Mar 1, 2024 at 4:18 AM Dmitri Popavenko wrote: > > Hi everyone, > > I am aware this is a parser issue, but is there any possibilit

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-30 Thread Gabor Grothendieck
args1 args2 args3 combined ## ## 1 %s plus %s equals %s 1 1 2 1 plus 1 equals 2 ## 2 %s plus %s equals %s 2 2 4 2 plus 2 equals 4 ## 3 %s plus %s equals %s 3 3 6 3 plus 3 equals 6 On Fri, Dec 29, 2023 at 1:45 PM Gabor Grothendieck wro

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Gabor Grothendieck
If the question is how to accomplish this as opposed to how to use eval then we can do it without eval like this provided we can assume that words contains three %s . library(dplyr) library(tidyr) df <- tibble(words=c("%s plus %s equals %s"),args=c("1,1,2","2,2,4","3,3,6")) df |> sepa

Re: [Rd] data.frame weirdness

2023-11-14 Thread Gabor Grothendieck
Seems like a leaky abstraction. If both representations are supposed to be outwardly the same to the user then they should act the same and if not then identical should not be TRUE. On Tue, Nov 14, 2023 at 9:56 AM Deepayan Sarkar wrote: > > On Tue, 14 Nov 2023 at 09:41, Gabor Grothe

Re: [Rd] data.frame weirdness

2023-11-14 Thread Gabor Grothendieck
Also why should that difference result in different behavior? On Tue, Nov 14, 2023 at 9:38 AM Gabor Grothendieck wrote: > > In that case identical should be FALSE but it is TRUE > > identical(a1, a2) > ## [1] TRUE > > > On Tue, Nov 14, 2023 at 8:58 AM Deepayan Sarka

Re: [Rd] data.frame weirdness

2023-11-14 Thread Gabor Grothendieck
t; [1] 3 > > Best, > -Deepayan > > On Tue, 14 Nov 2023 at 08:23, Gabor Grothendieck > wrote: > > > > What is going on here? In the lines ending in the inputs and outputs > > are identical yet one gives a warning and the other does not. > > > > a

[Rd] data.frame weirdness

2023-11-14 Thread Gabor Grothendieck
What is going on here? In the lines ending in the inputs and outputs are identical yet one gives a warning and the other does not. a1 <- `rownames<-`(anscombe[1:3, ], NULL) a2 <- anscombe[1:3, ] ix <- 5:8 # input arguments to are identical in both cases identical(stack(a1[ix]), sta

Re: [Rd] Multiple Assignment built into the R Interpreter?

2023-03-13 Thread Gabor Grothendieck
The gsubfn package can do that. library(gsubfn) # swap a and b without explicitly creating a temporary a <- 1; b <- 2 list[a,b] <- list(b,a) # get eigenvectors and eigenvalues list[eval, evec] <- eigen(cbind(1,1:3,3:1)) # get today's month, day, year requir

Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-08 Thread Gabor Grothendieck
ES = FALSE) > } > > gsub("^..", toupper, c("abc", "xyz")) > [1] "ABc" "XYz" > > But this isn't a simple change to replace() anymore, and I may just be > spending too much time tinkering with Julia. > > Steve > > On

Re: [Rd] Augment base::replace(x, list, value) to allow list= to be a predicate?

2023-03-07 Thread Gabor Grothendieck
This could be extended to sub and gsub as well which gsubfn in the gusbfn package already does: library(gsubfn) gsubfn("^..", toupper, c("abc", "xyz")) ## [1] "ABc" "XYz" On Fri, Mar 3, 2023 at 7:22 PM Pavel Krivitsky wrote: > > Dear All, > > Currently, list= in base::replace(x, list, valu

[Rd] summary.lm fails for difftime objects

2023-02-18 Thread Gabor Grothendieck
lm works with difftime objects but then if you try to get the summary it fails with an error: fit <- lm(as.difftime(Time, units = "mins") ~ demand, BOD) summary(fit) ## Error in Ops.difftime((f - mean(f)), 2) : ## '^' not defined for "difftime" objects A number of other lm methods also f

[Rd] package.skeleton hello* files

2023-02-14 Thread Gabor Grothendieck
Is there some way to avoid the automatic generation of hello* files in package.skeleton? I found that the following does it on Windows but then it does not create an R directory which I still want and also it gives warnings which I don't want. package.skeleton(code_files = "NUL") -- Statistics &

Re: [Rd] anova and intercept

2022-12-27 Thread Gabor Grothendieck
fit1, ~ -1) > anova(fit0, fit1) > > -pd > > > On 26 Dec 2022, at 13:49 , Gabor Grothendieck > > wrote: > > > > Suppose we want to perform a paired test using the sleep data frame > > with anova in R. Then this works and gives the same p value as > >

[Rd] anova and intercept

2022-12-26 Thread Gabor Grothendieck
Suppose we want to perform a paired test using the sleep data frame with anova in R. Then this works and gives the same p value as t.test(extra ~ group, sleep, paired = TRUE, var.equal = TRUE) ones <- rep(1, 10) anova(lm(diff(extra, 10) ~ ones + 0, sleep) This gives output but does not giv

[Rd] pipes and setNames

2022-04-17 Thread Gabor Grothendieck
When trying to transform names in a pipeline one can do the following where for this example we are making names upper case. BOD |> (\(x) setNames(x, toupper(names(x() but that seems a bit ugly and verbose. 1. One possibility is to enhance setNames to allow a function as a second argument.

[Rd] aggregate.formula and pipes

2022-01-26 Thread Gabor Grothendieck
Because aggregate.formula has a formula argument but the generic has an x argument neither of these work: mtcars |> aggregate(x = mpg ~ cyl, FUN = mean) mtcars |> aggregate(formula = mpg ~ cyl, FUN = mean) This does work: mtcars |> stats:::aggregate.formula(formula = mpg ~ cyl, FUN = mean)

[Rd] assignment

2021-12-27 Thread Gabor Grothendieck
In a recent SO post this came up (changed example to simplify it here). It seems that `test` still has the value sin. test <- sin environment(test)$test <- cos test(0) ## [1] 0 It appears to be related to the double use of `test` in `$<-` since if we break it up it works as expected:

Re: [Rd] order of operations

2021-08-27 Thread Gabor Grothendieck
t guaranteed should be > flagged by the language at compile time (or when interpreted) and refuse to > go on. > > All I can say with computer languages and adding ever more features, > with greater power comes greater responsibility and often greater > confusion. > > >

Re: [Rd] order of operations

2021-08-27 Thread Gabor Grothendieck
a reasonable answer can be extracted from a given body of data. > ~ John Tukey > > /// > > <https://www.inbo.be> > > > Op vr 27 aug. 2021 om 17:18 schreef Gabor Grothendieck < > ggrothendi...@gmail.com>: > >> Are there any guarantees

[Rd] order of operations

2021-08-27 Thread Gabor Grothendieck
Are there any guarantees of whether x will equal 1 or 2 after this is run? (x <- 1) * (x <- 2) ## [1] 2 x ## [1] 2 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-p

[Rd] problem with pipes, textConnection and read.dcf

2021-08-10 Thread Gabor Grothendieck
This gives an error bit if the first gsub line is commented out then there is no error even though it is equivalent code. L <- c("Variable:id", "Length:112630 ") L |> gsub(pattern = " ", replacement = "") |> gsub(pattern = " ", replacement = "") |> textConnection() |> read

Re: [Rd] Feature request: Change default library path on Windows

2021-07-25 Thread Gabor Grothendieck
At the very least it would be nice if there were a function that displays all the locations/paths currently being used in R. On Sat, Jul 24, 2021 at 6:15 PM Steve Haroz wrote: > > Hello, > > I'd like to propose moving the default library install location on Windows > from: > %USERPROFILE%/Docume

Re: [Rd] S3 weirdness

2021-06-24 Thread Gabor Grothendieck
e_0.20-44 > > which includes S3 method dispatch tables: > > > methods(as.ts) > [1] as.ts.default* as.ts.zoo* as.ts.zooreg* > see '?methods' for accessing help and source code > > so the behavior is as expected. > > Cheers, > Simon > > > > On 25/06/2021

[Rd] S3 weirdness

2021-06-24 Thread Gabor Grothendieck
If we start up a vanilla session of R with no packages loaded and type the single line of code below as the first line entered then we get the output shown below. The NA in the output and the length of 7 indicate that as.ts dispatched as.ts.zoo since as.ts.default would have resulted in a length o

Re: [Rd] Additional an example for the forward pipe operator's documentation

2021-06-19 Thread Gabor Grothendieck
These also work in this particular case although not in general and the Call: line in the output differs: mtcars |> subset(cyl == 4) |> with(lm(mpg ~ disp)) mtcars |> with(lm(mpg ~ disp, subset = cyl == 4)) On Sat, Jun 19, 2021 at 7:23 AM Erez Shomron wrote: > > Hello, > > > While playing ar

Re: [Rd] reshape documentation

2021-04-11 Thread Gabor Grothendieck
One thing about varying is that reshape ignores the names on the varying list and makes you specify them all over again even though it could know what they are. Note that we had to specify that names(varying) is the v.names. DF <- structure(list(A1 = 10L, A2 = 5L, B1 = 11L, B2 = 5L, C1 = 21L,

[Rd] replicate evaluates its second argument in wrong environment

2021-02-13 Thread Gabor Grothendieck
Currently replicate used within sapply within a function can fail because it gets the environment for its second argument, which is currently hard coded to be the parent frame, wrong. See this link for a full example of how it goes wrong and how it could be made to work if it were possible to pass

Re: [Rd] brief update on the pipe operator in R-devel

2021-01-15 Thread Gabor Grothendieck
These are documented but still seem like serious deficiencies: > f <- function(x, y) x + 10*y > 3 |> x => f(x, x) Error in f(x, x) : pipe placeholder may only appear once > 3 |> x => f(1+x, 1) Error in f(1 + x, 1) : pipe placeholder must only appear as a top-level argument in the RHS call Also

Re: [Rd] [External] Re: New pipe operator

2020-12-09 Thread Gabor Grothendieck
On Wed, Dec 9, 2020 at 12:36 PM Gabriel Becker wrote: > I mean, I think the bizarro pipe was a pretty clever piece of work. I was > impressed by what John did there, but I don't really know what you're > suggesting here. As you say, the bizarro pipe works now without any changes > and you're we

Re: [Rd] [External] Re: New pipe operator

2020-12-09 Thread Gabor Grothendieck
On Wed, Dec 9, 2020 at 10:08 AM Duncan Murdoch wrote: > > You might be interested in this blog post by Michael Barrowman: > > https://michaelbarrowman.co.uk/post/the-new-base-pipe/ > > He does some timing comparisons, and the current R-devel implementations > of |> and \() do quite well. It does

Re: [Rd] the pipe |> and line breaks in pipelines

2020-12-09 Thread Gabor Grothendieck
On Wed, Dec 9, 2020 at 4:03 AM Timothy Goodman wrote: > But the bigger issue happens when I want to re-run just *part* of the > pipeline. Insert one of the following into the pipeline. It does not require that you edit any lines. It only involves inserting a line. print %>% { str(.); . } %

Re: [Rd] [External] Re: New pipe operator

2020-12-08 Thread Gabor Grothendieck
On Mon, Dec 7, 2020 at 9:09 AM Gabor Grothendieck wrote: > > On Sat, Dec 5, 2020 at 1:19 PM wrote: > > Let's get some experience > > Here is my last SO post using dplyr rewritten to use R 4.1 devel. Seems It occurred to me it would also be interesting to show this examp

Re: [Rd] [External] anonymous functions

2020-12-08 Thread Gabor Grothendieck
On Mon, Dec 7, 2020 at 12:34 PM wrote: > I don't disagree in principle, but the reality is users want shortcuts > and as a result various packages, in particular tidyverse, have been > providing them. Mostly based on formulas, mostly with significant > issues since formulas weren't designed for th

Re: [Rd] New pipe operator

2020-12-08 Thread Gabor Grothendieck
Duncan Murdoch: > I agree it's all about call expressions, but they aren't all being > treated equally: > > x |> f(...) > > expands to f(x, ...), while > > x |> `function`(...) > > expands to `function`(...)(x). This is an exception to the rule for Yes, this is the problem. It is trying to handl

Re: [Rd] New pipe operator

2020-12-07 Thread Gabor Grothendieck
On Mon, Dec 7, 2020 at 2:02 PM Kevin Ushey wrote: > > IMHO the use of anonymous functions is a very clean solution to the > placeholder problem, and the shorthand lambda syntax makes it much > more ergonomic to use. Pipe implementations that crawl the RHS for > usages of `.` are going to be more e

Re: [Rd] New pipe operator

2020-12-07 Thread Gabor Grothendieck
On Mon, Dec 7, 2020 at 12:54 PM Duncan Murdoch wrote: > An advantage of the current implementation is that it's simple and easy > to understand. Once you make it a user-modifiable binary operator, > things will go kind of nuts. > > For example, I doubt if there are many users of magrittr's pipe w

Re: [Rd] anonymous functions

2020-12-07 Thread Gabor Grothendieck
It is easier to understand a function if you can see the entire function body at once on a page or screen and excessive verbosity interferes with that. On Mon, Dec 7, 2020 at 12:04 PM Therneau, Terry M., Ph.D. via R-devel wrote: > > “The shorthand form \(x) x + 1 is parsed as function(x) x + 1. I

Re: [Rd] [External] Re: New pipe operator

2020-12-07 Thread Gabor Grothendieck
On Mon, Dec 7, 2020 at 10:11 AM wrote: > Or, keeping dplyr but with R-devel pipe and function shorthand: > > DF <- "myfile.csv" %>% > readLines() |> > \(.) gsub(r'{(c\(.*?\)|integer\(0\))}', r'{"\1"}', .) |> > \(.) read.csv(text = .) |> > mutate(across(2:3, \(col) lapply(col, \(x)

Re: [Rd] New pipe operator

2020-12-07 Thread Gabor Grothendieck
One could examine how magrittr works as a reference implementation if there is a question on how something should function. It's in widespread use and seems to work well. On Mon, Dec 7, 2020 at 10:20 AM Deepayan Sarkar wrote: > > On Mon, Dec 7, 2020 at 6:53 PM Gabor Grothendie

Re: [Rd] [External] Re: New pipe operator

2020-12-07 Thread Gabor Grothendieck
On Sat, Dec 5, 2020 at 1:19 PM wrote: > Let's get some experience Here is my last SO post using dplyr rewritten to use R 4.1 devel. Seems not too bad. Was able to work around the placeholder for gsub by specifying the arg names and used \(...)... elsewhere. This does not address the inconsiste

Re: [Rd] New pipe operator

2020-12-07 Thread Gabor Grothendieck
On Mon, Dec 7, 2020 at 5:41 AM Duncan Murdoch wrote: > I agree it's all about call expressions, but they aren't all being > treated equally: > > x |> f(...) > > expands to f(x, ...), while > > x |> `function`(...) > > expands to `function`(...)(x). This is an exception to the rule for > other cal

Re: [Rd] New pipe operator

2020-12-06 Thread Gabor Grothendieck
This is really irrelevant. On Sun, Dec 6, 2020 at 9:23 PM Gabriel Becker wrote: > > Hi Gabor, > > On Sun, Dec 6, 2020 at 3:22 PM Gabor Grothendieck > wrote: >> >> I understand very well that it is implemented at the syntax level; >> however, in any case the im

Re: [Rd] New pipe operator

2020-12-06 Thread Gabor Grothendieck
t is a matter of breaking the way R works as a functional language with first class functions. On Sun, Dec 6, 2020 at 4:06 PM Gabriel Becker wrote: > > Hi Gabor, > > On Sun, Dec 6, 2020 at 12:52 PM Gabor Grothendieck > wrote: >> >> I think the real issue here is that

Re: [Rd] New pipe operator

2020-12-06 Thread Gabor Grothendieck
using it can change that inconsistency which seems serious to me and needs to be addressed even if it complicates the implementation since it drives to the heart of what R is. On Sat, Dec 5, 2020 at 1:08 PM Gabor Grothendieck wrote: > > The construct utils::head is not that common but bare

Re: [Rd] [External] Re: New pipe operator

2020-12-06 Thread Gabor Grothendieck
Why is that ambiguous? It works in magrittr. > library(magrittr) > 1 %>% `+`() [1] 1 On Sun, Dec 6, 2020 at 1:09 PM wrote: > > On Sun, 6 Dec 2020, Gabor Grothendieck wrote: > > > The following gives an error. > > > > 1 |> `+`(2) > > ## Error: f

Re: [Rd] [External] Re: New pipe operator

2020-12-06 Thread Gabor Grothendieck
The following gives an error. 1 |> `+`(2) ## Error: function '+' is not supported in RHS call of a pipe 1 |> `+`() ## Error: function '+' is not supported in RHS call of a pipe but this does work: 1 |> (`+`)(2) ## [1] 3 1 |> (`+`)() ## [1] 1 The error message suggests

Re: [Rd] installling R-devel on Windows

2020-12-06 Thread Gabor Grothendieck
I meant on the R devel download page. (I was just installing Rtools40 on another computer.) On Sun, Dec 6, 2020 at 10:27 AM Gabor Grothendieck wrote: > > I tried it from another computer and it did work. Is there some way > of installing R devel using the analog of the R --vanilla fla

Re: [Rd] installling R-devel on Windows

2020-12-06 Thread Gabor Grothendieck
to what occurs. I don't see anything documenting flags on the Rtools40 page. On Sat, Dec 5, 2020 at 9:52 AM Gabor Grothendieck wrote: > > I clicked on the download link at > https://cran.r-project.org/bin/windows/base/rdevel.html > and then opened the downloaded file which starts

Re: [Rd] as.POSIXct.numeric change default of origin argument

2020-12-06 Thread Gabor Grothendieck
For example, this works: library(zoo) as.Date(0) ## [1] "1970-01-01" On Sun, Dec 6, 2020 at 7:10 AM Achim Zeileis wrote: > > On Sun, 6 Dec 2020, Jan Gorecki wrote: > > > Hello all, > > > > I would like to propose to change the default value for "origin" > > argument in as.POSIXct.numeric m

Re: [Rd] New pipe operator

2020-12-05 Thread Gabor Grothendieck
The construct utils::head is not that common but bare functions are very common and to make it harder to use the common case so that the uncommon case is slightly easier is not desirable. Also it is trivial to write this which does work: mtcars %>% (utils::head) On Sat, Dec 5, 2020 at 11:59 AM

Re: [Rd] installling R-devel on Windows

2020-12-05 Thread Gabor Grothendieck
encountered this. On Sat, Dec 5, 2020 at 9:13 AM Jeroen Ooms wrote: > > On Sat, Dec 5, 2020 at 3:00 PM Gabor Grothendieck > wrote: > > > > When I try to install r-devel on Windows all I get is this. No other > > files. This also occurred yesterday as well. > >

[Rd] installling R-devel on Windows

2020-12-05 Thread Gabor Grothendieck
When I try to install r-devel on Windows all I get is this. No other files. This also occurred yesterday as well. Directory of C:\Program Files\R\R-test 12/05/2020 08:56 AM . 12/05/2020 08:56 AM .. 12/05/2020 08:56 AM11,503 unins000.dat 12/05/2020 08:5

Re: [Rd] ftable <-> data.frame etc {was "justify hard coded in format.ftable"}

2020-05-23 Thread Gabor Grothendieck
A Female 89 19 ## 3 B Male 353 207 ## 4 B Female 178 ## ... etc ... Fri, May 15, 2020 at 12:25 PM Martin Maechler wrote: > > >>>>> Gabor Grothendieck > >>>>> on Thu, 14 May 2020 06:56:06 -0400 writes

Re: [Rd] justify hard coded in format.ftable

2020-05-15 Thread Gabor Grothendieck
If you are looking at ftable could you also consider adding a way to convert an ftable into a usable data.frame such as the ftable2df function defined here: https://stackoverflow.com/questions/11141406/reshaping-an-array-to-data-frame/11143126#11143126 and there is an example of using it here:

Re: [Rd] justify hard coded in format.ftable

2020-05-15 Thread Gabor Grothendieck
One can use as.data.frame(as.matrix(tab)) to avoid calling as.data.frame.matrix directly (although I find I do use as.data.frame.matrix anyways sometimes even though it is generally better to call the generic.). Also note that the various as.data.frame methods do not address the examples in the

Re: [Rd] suggestion: "." in [lsv]apply()

2020-04-20 Thread Gabor Grothendieck
iple purposes. library(sqldf) mytime <- 4 fn$sqldf("select * from BOD where Time < $mytime") On Mon, Apr 20, 2020 at 9:32 AM Sokol Serguei wrote: > > Le 19/04/2020 à 20:46, Gabor Grothendieck a écrit : > > You can get pretty close to that already using fn$ in the gsubf

Re: [Rd] suggestion: "." in [lsv]apply()

2020-04-19 Thread Gabor Grothendieck
You can get pretty close to that already using fn$ in the gsubfn package: > library(gsubfn) > fn$sapply(split(mtcars, mtcars$cyl), x ~ summary(lm(mpg ~ wt, x))$r.squared) 4 6 8 0.5086326 0.4645102 0.4229655 It is not specific to sapply but rather fn$ can preface most funct

Re: [Rd] New matrix function

2019-10-11 Thread Gabor Grothendieck
The link you posted used the same inputs as in my example. If that is not what you meant maybe a different example is needed. Regards. On Fri, Oct 11, 2019 at 2:39 PM Pages, Herve wrote: > > Has someone looked into the image processing area for this? That sounds > a little bit too high-level for

Re: [Rd] New matrix function

2019-10-11 Thread Gabor Grothendieck
I pressed return too soon. If we had such a multiply then which(embed(A, x) %==.&% reverse(x)) On Fri, Oct 11, 2019 at 10:57 AM Gabor Grothendieck wrote: > > Also note that the functionality discussed could be regarded as a > generalization > of matrix multiplication wh

Re: [Rd] New matrix function

2019-10-11 Thread Gabor Grothendieck
Also note that the functionality discussed could be regarded as a generalization of matrix multiplication where * and + are general functions and in this case we have * replaced by == and + replaced by &. On Fri, Oct 11, 2019 at 10:46 AM Gabor Grothendieck wrote: > > Using the exam

Re: [Rd] New matrix function

2019-10-11 Thread Gabor Grothendieck
Using the example in the link here are two one-liners: A <- c(2,3,4,1,2,3,4,1,1,2) x <- c(1,2) # 1 - zoo library(zoo) which( rollapply(A, length(x), identical, x, fill = FALSE, align = "left") ) ## [1] 4 9 # 2 - Base R using conversion to character gregexpr(paste(x, collapse = ""

Re: [Rd] Recall

2018-09-23 Thread Gabor Grothendieck
Please ignore. Looking at this again I realize the problem is that Recall is not direclty within my.compose2 but rather is within the anonymous function in the else. On Sun, Sep 23, 2018 at 9:23 AM Gabor Grothendieck wrote: > > This works: > > my.compose <- function(f, ...) { &g

[Rd] Recall

2018-09-23 Thread Gabor Grothendieck
This works: my.compose <- function(f, ...) { if (missing(f)) identity else function(x) f(my.compose(...)(x)) } my.compose(sin, cos, tan)(pi/4) ## [1] 0.5143953 sin(cos(tan(pi/4))) ## [1] 0.5143953 But replacing my.compose with Recall in the else causes it to fail: my.comp

Re: [Rd] apply with zero-row matrix

2018-07-30 Thread Gabor Grothendieck
Try pmap and related functions in purrr: pmap(as.data.frame(m), ~ { cat("Called...\n"); print(c(...)) }) ## list() On Mon, Jul 30, 2018 at 12:33 AM, David Hugh-Jones wrote: > Forgive me if this has been asked many times before, but I couldn't find > anything on the mailing lists. > > I'd exp

[Rd] odd behavior of names

2018-07-29 Thread Gabor Grothendieck
The first component name has backticks around it and the second does not. Though not wrong, it seems inconsistent. list(a = 1, b = 2) ## $`a` ## [1] 1 ## ## $b ## [1] 2 R.version.string ## [1] "R version 3.5.1 Patched (2018-07-02 r74950)" -- Statistics & Software Consulting GKX Group, GKX Ass

Re: [Rd] oddity in transform

2018-07-24 Thread Gabor Grothendieck
0 349 44 50 | > i...@dans.knaw.nl <mailto:i...@dans.kn> | dans.knaw.nl > > DANS is an institute of the Dutch Academy KNAW <http://knaw.nl/nl> and > funding organisation NWO <http://www.nwo.nl/>. > > On 23/07/2018, 16:52, "R-devel on behalf of Gabor Grothendie

[Rd] oddity in transform

2018-07-23 Thread Gabor Grothendieck
Note the inconsistency in the names in these two examples. X.Time in the first case and Time.1 in the second case. > transform(BOD, X = BOD[1:2] * seq(6)) Time demand X.Time X.demand 118.3 1 8.3 22 10.3 4 20.6 33 19.0 9 57.0 44 1

Re: [Rd] Setting the path to Rtools for package compilation on Windows

2018-02-14 Thread Gabor Grothendieck
If there is work going on to improve Rtools 1. one of the most annoying aspects of it is that it does not play nice with builtin Windows commands. In particular, it defines a command called find which works like UNIX find but it masks Windows find if you add the Rtools folders to your PATH making

Re: [Rd] A few suggestions and perspectives from a PhD student

2017-05-05 Thread Gabor Grothendieck
Regarding the anonymous-function-in-a-pipeline point one can already do this which does use brackets but even so it involves fewer characters than the example shown. Here { . * 2 } is basically a lambda whose argument is dot. Would this be sufficient? library(magrittr) 1.5 %>% { . * 2 } ##

Re: [Rd] RFC: tapply(*, ..., init.value = NA)

2017-01-27 Thread Gabor Grothendieck
If xtabs is enhanced then as.data.frame.table may also need to be modified so that it continues to be usable as an inverse, at least to the degree feasible. On Thu, Jan 26, 2017 at 5:42 AM, Martin Maechler wrote: > Last week, we've talked here about "xtabs(), factors and NAs", > -> https://sta

Re: [Rd] On implementing zero-overhead code reuse

2016-10-03 Thread Gabor Grothendieck
Have a look at the CRAN modules package and the import package. On Sun, Oct 2, 2016 at 1:29 PM, Kynn Jones wrote: > I'm looking for a way to approximate the "zero-overhead" model of code > reuse available in languages like Python, Perl, etc. > > I've described this idea in more detail, and the mo

Re: [Rd] strcapture enhancement

2016-09-21 Thread Gabor Grothendieck
Note that read.pattern in gsubfn does accept stringsAsFactors = FALSE, e.g. using your input lines and pattern: library(gsubfn) Lines <- c("Three 3", "Twenty 20") pat <- "([[:alpha:]]*) +([[:digit:]]*)" s2 <- read.pattern(text = Lines, pattern = pat, stringsAsFactors = FALSE, col.names = c("Name

Re: [Rd] stack problem

2016-06-27 Thread Gabor Grothendieck
)) or sort them, > too? > > On Mon, Jun 27, 2016 at 10:39 AM, Gabor Grothendieck > wrote: >> stack() seems to drop empty levels. Perhaps there could be a >> drop=FALSE argument if one wanted all the original levels. In the >> example below, we may wish to retain l

[Rd] stack problem

2016-06-27 Thread Gabor Grothendieck
stack() seems to drop empty levels. Perhaps there could be a drop=FALSE argument if one wanted all the original levels. In the example below, we may wish to retain level "b" in s$ind even though component LL$b has length 0. > LL <- list(a = 1:3, b = list()) > s <- stack(LL) > str(s) 'data.frame'

[Rd] ctrl-R in Rgui

2016-05-05 Thread Gabor Grothendieck
When in the Rgui editor sometimes ctrl-R does not cause anything to be sent to the R console. It can be reproduced like this: - when in the Rgui console press ctrl-F N to get a new editor window - enter: pi + 3 followed by Enter - while still in the editor window press ctrl-A ctrl-R and pi + 3 ge

[Rd] for in r-devel

2016-03-18 Thread Gabor Grothendieck
Regarding, this news item for r-devel: ‘for()’ loops are generalized to iterate over any object with ‘[[’ and ‘length()’ methods. Thanks to Hervé Pagès for the idea and the patch. Below dd is an object for which [[ and length work but the result is still numeric rather than Date class in "R Unde

Re: [Rd] Puzzled by eval

2015-11-06 Thread Gabor Grothendieck
This code which I think I wrote but might have gotten from elsewhere a long time ago shows the environments that are searched from a given function, in this case chart.RelativePerformance in PerformanceAnalytics package. Try it on some of your functions in and out of packages to help determine th

Re: [Rd] returnValue()

2015-05-22 Thread Gabor Grothendieck
Please disregard. I was running an older version of R at the time. In R version 3.2.0 Patched (2015-04-19 r68205) returnValue() does work. On Fri, May 22, 2015 at 6:25 PM, Gabor Grothendieck wrote: > In R devel rev.66393 (2014-08-15) it was possible to do this: > >trace(optim, exi

[Rd] returnValue()

2015-05-22 Thread Gabor Grothendieck
In R devel rev.66393 (2014-08-15) it was possible to do this: trace(optim, exit = quote(str(returnValue( but returnValue() does not seem to be available any more. The above was useful to get the output of a function when it was called deep within another function that I have no control ov

Re: [Rd] xtabs and NA

2015-02-09 Thread Gabor Grothendieck
On Mon, Feb 9, 2015 at 8:52 AM, Kirill Müller wrote: > Hi > > > I haven't found a way to produce a tabulation from factor data with NA > values using xtabs. Please find a minimal example below, it's also on R-pubs > [1]. Tested with R 3.1.2 and R-devel r67720. > > It doesn't seem to be documented

Re: [Rd] CRAN and ggplot2 geom and stat extensions

2014-12-23 Thread Gabor Grothendieck
On Tue, Dec 23, 2014 at 11:21 AM, Ista Zahn wrote: > On Tue, Dec 23, 2014 at 10:34 AM, Frank Harrell > wrote: >> I am thinking about adding several geom and stat extensions to ggplot2 >> in the Hmisc package. To do this requires using non-exported ggplot2 >> functions as discussed in >> http://s

Re: [Rd] Options that are local to the package that sets them

2014-10-31 Thread Gabor Grothendieck
On Fri, Oct 31, 2014 at 8:43 PM, Gábor Csárdi wrote: > On Fri, Oct 31, 2014 at 8:10 PM, Gabor Grothendieck > wrote: > [...] >>> Is there a better way? I have a feeling that this is already supported >>> somehow, I just can't find out how. >>> >>

Re: [Rd] Options that are local to the package that sets them

2014-10-31 Thread Gabor Grothendieck
On Fri, Oct 31, 2014 at 7:34 PM, Gábor Csárdi wrote: > Dear All, > > I am trying to do the following, and could use some hints. > > Suppose I have a package called pkgA. pkgA exposes an API that > includes setting some options, e.g. pkgA works with color palettes, > and the user of the package can

Re: [Rd] Using Rtools with gcc 4.8.3

2014-10-05 Thread Gabor Grothendieck
On Sun, Oct 5, 2014 at 6:51 AM, Uwe Ligges wrote: > > > On 05.10.2014 12:20, Jeroen Ooms wrote: >> >> I started working on some R bindings for mongo-c-driver [1]. The C >> library compiles fine on Ubuntu Trusty (gcc 4.8.2) and osx (clang), >> however on my windows machine (gcc 4.6.3 from Rtools 3.

Re: [Rd] Re R CMD check checking in development version of R

2014-08-28 Thread Gabor Grothendieck
Yes, Depends certainly has a role. The ability of one package to automatically provide all the facilities of another package to the user is important. There are many situations where the functionality you want to provide to the user is split among multiple packages. For example, 1. xts uses zoo a

Re: [Rd] Licence for datasets in a R-package

2014-07-21 Thread Gabor Grothendieck
On Mon, Jul 21, 2014 at 12:54 PM, Gábor Csárdi wrote: > In practice, CRAN maintainers do not allow multiple licenses for parts > of the same package. At least they did not for my package a couple of > months ago. > If that is the case then you could put your data files in a separate package from

[Rd] useDynLib

2014-07-06 Thread Gabor Grothendieck
I would like to be able to load two versions of a package at once and to do that was thinking of giving each version a different package name in the DESCRIPTION file and the building and installing each such version separately. library(myPkg1) library(myPkg2) and then use myPkg1::myFun() and myPk

Re: [Rd] type.convert and doubles

2014-04-19 Thread Gabor Grothendieck
On Sat, Apr 19, 2014 at 1:06 PM, Simon Urbanek wrote: > On Apr 19, 2014, at 9:00 AM, Martin Maechler > wrote: > > I think there should be two separate discussions: > > a) have an option (argument to type.convert and possibly read.table) to > enable/disable this behavior. I'm strongly in favor o

Re: [Rd] Can the output of Sys.getenv() be improved?

2014-04-18 Thread Gabor Grothendieck
On Fri, Apr 18, 2014 at 12:38 PM, Zhang,Jun wrote: > Within an R session, type Sys.getenv() will list all the environment > variables, but each one of them occupies about a page, so scrolling to find > one is difficult. Is this because I don't know how to use it or something > could be improved

Re: [Rd] type.convert and doubles

2014-04-17 Thread Gabor Grothendieck
On Thu, Apr 17, 2014 at 2:21 PM, Murray Stokely wrote: > If you later want to do arithmetic on them, you can choose to lose > precision by using as.numeric() or use one of the large number > packages on CRAN (GMP, int64, bit64, etc.). But once you've dropped > the precision with as.numeric you ca

Re: [Rd] R 3.1.0 and C++11

2014-04-10 Thread Gabor Grothendieck
On Tue, Oct 29, 2013 at 1:58 AM, wrote: > Le 2013-10-29 03:01, Whit Armstrong a écrit : > >> I would love to see optional c++0x support added for R. > > > c++0x was the name given for when this was in development. Now c++11 is a > published standard backed by implementations by major compilers. >

  1   2   3   4   5   6   7   8   9   10   >