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

Attempt at sha1.formula Method #122

Closed
billdenney opened this issue Oct 12, 2019 · 2 comments · Fixed by #123
Closed

Attempt at sha1.formula Method #122

billdenney opened this issue Oct 12, 2019 · 2 comments · Fixed by #123

Comments

@billdenney
Copy link
Contributor

billdenney commented Oct 12, 2019

I just tried to write an sha1.formula method (as mentioned in #23), but I couldn't get the test to work. My attempts were:

Function:

sha1.formula <- function(x, digits = 14L, zapsmall = 7L, ..., algo = "sha1"){
    dots <- list(...)
    if (is.null(dots$environment)) {
        dots$environment <- TRUE
    }
    if (isTRUE(dots$environment)) {
        y <- append(
            as.list(x),
            list(environment = digest(environment(x), algo = algo))
        )
    } else {
        y <- as.list(x)
    }
    y <- vapply(
        y,
        sha1,
        digits = digits,
        zapsmall = zapsmall,
        environment = dots$environment,
        ... = dots,
        algo = algo,
        FUN.VALUE = NA_character_
    )
    attr(y, "digest::sha1") <- attr_sha1(
        x = y, digits = digits, zapsmall = zapsmall, algo = algo, dots
    )
    digest(y, algo = algo)
}

Test:

x.formula <- a~b+c|d
expect_true(
    identical(
        sha1(x.formula, environment=FALSE),
        {
            y <- sapply(
                X=as.list(x.formula),
                FUN=sha1
            )
            attr(y, "digest::sha1") <- list(
                digits=14L,
                zapsmall=7L,
                algo="sha1"
            )
            sha1(y)
        }
    )
)

Edited to add the formula being tested.

@billdenney
Copy link
Contributor Author

billdenney commented Oct 13, 2019

I've traced my issue to the fact that the right hand side of the formula which becomes a call evaluates to a different result when inside or outside of the function. That appears to be an issue with sha1.call() (and within that, digest) giving a different result. I will try to make a reproducible example and open a new issue for that.

Nevermind, this was an issue where I wasn't setting the attributes correctly.

@billdenney
Copy link
Contributor Author

I have found my issue, and I'm finalizing the PR now.

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

Successfully merging a pull request may close this issue.

1 participant