Displaying 5 results from an estimated 5 matches for "comprehenr".
Did you mean:
comprehend
2024 Jun 16
2
slowness when I use a list comprehension
Dear RHelp-list,
?? I try to use the package comprehenr to replace a for loop by a list
comprehension.
?I wrote the code but I certainly miss something because it is very
slower compared to the for loops. May you please explain to me why the
list comprehension is slower in my case.
Here is my example. I do the calculation of the square difference...
2024 Jun 16
1
slowness when I use a list comprehension
...ote, many, myself included, really appreciate alternate
ways to do things and heavily use tidyverse packages that mostly are not
base R but sort of a grafted-on other language. So what? Purists don't
necessarily do well in the real world.
On the topic at hand and speed, I went an looked at the comprehenr package
and it is no wonder it is slower.
Here is the code Laurent used in calling to_vec:
> to_vec
function (expr, recursive = TRUE, use.names = FALSE)
{
res = eval.parent(substitute(comprehenr::to_list(expr)))
unlist(res, recursive = recursive, use.names = use.names)
}'
It does...
2024 Jun 16
1
slowness when I use a list comprehension
...ow that I know it is available.
>
>As to why you see your example as slow, I see you used a fairly complex and nested expression and wonder if it was a better way to go. As you are dealing with an interpreter doing delayed evaluation, I can imagine reasons it can be slow. But note the package comprehenr may not be designed to be more efficient than loops or of the more built-in functional methods that can be faster. The package is there perhaps more as a compatibility helper that allows you to write closer to the python style and perhaps re-shapes what you wrote into a set of instructions in more...
2024 Jun 16
1
slowness when I use a list comprehension
...t in R now that I know it is available.
As to why you see your example as slow, I see you used a fairly complex and nested expression and wonder if it was a better way to go. As you are dealing with an interpreter doing delayed evaluation, I can imagine reasons it can be slow. But note the package comprehenr may not be designed to be more efficient than loops or of the more built-in functional methods that can be faster. The package is there perhaps more as a compatibility helper that allows you to write closer to the python style and perhaps re-shapes what you wrote into a set of instructions in more...
2024 Jun 16
1
slowness when I use a list comprehension
...d. Try
ix <- seq_along(vec2)
S_diff2 <- sapply(seq_len(N1-(N2-1)*ratio_sampling), \(j)
sum((vec1[(ix-1)*ratio_sampling+j] - vec2[ix])**2))
On Sun, Jun 16, 2024 at 11:27?AM Laurent Rhelp <laurentRHelp at free.fr> wrote:
>
> Dear RHelp-list,
>
> I try to use the package comprehenr to replace a for loop by a list
> comprehension.
>
> I wrote the code but I certainly miss something because it is very
> slower compared to the for loops. May you please explain to me why the
> list comprehension is slower in my case.
>
> Here is my example. I do the calcula...