Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique.fact() needed #86

Closed
jmbarbone opened this issue Jan 20, 2022 · 1 comment · Fixed by #101
Closed

unique.fact() needed #86

jmbarbone opened this issue Jan 20, 2022 · 1 comment · Fixed by #101
Labels
new feature 🎁 New feature request
Milestone

Comments

@jmbarbone
Copy link
Owner

unique.default() rebuilds factors -- which leaves off the fact class

library(mark)
str(unique(fact(1:4)))
#>  Factor w/ 4 levels "1","2","3","4": 1 2 3 4

unique.default
#> function (x, incomparables = FALSE, fromLast = FALSE, nmax = NA, 
#>     ...) 
#> {
#>     if (!is.object(x)) 
#>         return(.Internal(unique(x, incomparables, fromLast, nmax)))
#>     if (is.factor(x)) {
#>         z <- .Internal(unique(x, incomparables, fromLast, min(length(x), 
#>             nlevels(x) + 1L)))
#>         return(factor(z, levels = seq_len(nlevels(x)), labels = levels(x), 
#>             ordered = is.ordered(x)))
#>     }
#>     z <- .Internal(unique(x, incomparables, fromLast, nmax))
#>     if (inherits(x, "POSIXct")) 
#>         structure(z, class = class(x), tzone = attr(x, "tzone"))
#>     else if (inherits(x, "Date")) 
#>         structure(z, class = class(x))
#>     else z
#> }
#> <bytecode: 0x0000000013dd7e18>
#> <environment: namespace:base>

Created on 2022-01-20 by the reprex package (v2.0.1)

@jmbarbone jmbarbone added the new feature 🎁 New feature request label Jan 20, 2022
@jmbarbone jmbarbone added this to the 0.4.3 milestone Jan 20, 2022
@jmbarbone
Copy link
Owner Author

With enhancements from #69 , this could be:

unique.fact <- function(x, ...) {
  att <- attributes(x)
  struct(
    att$uniques,
    class = att$class,
    levels = att$levels,
    unique = att$unique,
    na = att$na
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature 🎁 New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant