RobinHankin / hyper2

https://robinhankin.github.io/hyper2/
5 stars 3 forks source link

enhancement of powers() #101

Open RobinHankin opened 3 years ago

RobinHankin commented 3 years ago

Issue #100 notwithstanding, look at this:

> icons
log(L^24 * (L + NB + OA + THC)^-20 * (L + NB + OA + WAIS)^-9 * (L + NB
+ THC + WAIS)^-15 * (L + OA + PB + THC)^-11 * (L + OA + PB + WAIS)^-18
* (L + PB + THC + WAIS)^-16 * NB^32 * (NB + OA + PB + THC)^-18 * (NB +
OA + PB + WAIS)^-8 * (NB + PB + THC + WAIS)^-18 * OA^14 * PB^30 *
THC^24 * WAIS^9)
> a <- powers(icons)
> names(a) <- sapply(brackets(icons),paste,collapse=" ")
> a
             L    L NB OA THC   L NB OA WAIS  L NB THC WAIS    L OA PB THC 
            24            -20             -9            -15            -11 
  L OA PB WAIS  L PB THC WAIS             NB   NB OA PB THC  NB OA PB WAIS 
           -18            -16             32            -18             -8 
NB PB THC WAIS             OA             PB            THC           WAIS 
           -18             14             30             24              9 
> 

It took me some time to arrive at the idiom needed to set the names of a nicely. It might be good to include such names in powers().

RobinHankin commented 3 years ago

This will have to change now that disordR is used for powers():

> a <- powers(icons)
> a
A disord object with hash ad0406e6ee0113993b786b4e0eaff22259afed97 and elements
 [1]  24 -20  -9 -15 -11 -18 -16  32 -18  -8 -18  14  30  24   9
(in some order)
> names(a) <- sapply(brackets(icons),paste,collapse=" ")
> a
A disord object with hash ad0406e6ee0113993b786b4e0eaff22259afed97 and elements
 [1]  24 -20  -9 -15 -11 -18 -16  32 -18  -8 -18  14  30  24   9
(in some order)
> 

(above, we see that the names attribute is not taken up).

RobinHankin commented 10 months ago

The returned object should be of class frab:

namedpowers <- function(H){
  frab(setNames(elements(powers(H)),sapply(elements(brackets(H)),paste,collapse=" ")))
}