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

Check if supplying named arguments works with logged functions #7

Open
b-rodrigues opened this issue Jul 19, 2022 · 4 comments
Open

Comments

@b-rodrigues
Copy link
Owner

Noticed that r_unique <- record(data.table:::unique.data.table)

then r_unique(a, by = c(x,y)) seems to ignore by argument

@b-rodrigues
Copy link
Owner Author

b-rodrigues commented Jun 9, 2023

mode <- function(x) {
  ux <- unique(x)
  ux[which.max(tabulate(match(x, ux)))]
}
vetor <- c(3,1,2,5,9,3,2,2,5,8,4,1)
mode(x=vetor)
# decorate function
r_mode <- record(mode, .g = length, diff = 'none')
# this works
res <- r_mode(vetor)
read_log(res)
check_g(res)
# this doesn’t
r_mode(x=vetor)
# if the function has several arguments, we can name the second but not the first
soma2 <- function(x, y){
  res <- x+y
  
  return(res)
}

soma2(x=2, y=6)
# this works
r_soma2 <- record(soma2, .g = length, diff = 'none')

r_soma2(2,6)

r_soma2(2, y=6)
# this doesn’t
r_soma2(x=2,y=6)

@MatousEibich any ideas? I’ll try some things out this weekend

@MatousEibich
Copy link
Collaborator

@b-rodrigues Looked into it a little bit. I have a question related to this issue - why do we need .value (mainly in purely())? My understanding is that it's a placeholder for the first argument of the function being recorded. Can't we just use dynamic dots without .value and then change the code in purely to something like:

if(all(purrr::map_lgl(args, maybe::is_nothing))){

      final_result <- list(
        value = maybe::nothing(),
        log_df = "A `Nothing` was given as input."
      )

    } 

Is my understanding correct or am I missing something?

@b-rodrigues
Copy link
Owner Author

sorry, I'm suuuuuuper late, but seems you're right! I've started fixing this issue in the fixing_issue7 branch.

@b-rodrigues
Copy link
Owner Author

hmm actually keeping .value seems to be important, especially for functions with NSE (dplyr, mainly). Basically a decorated function has its first argument overwritten to .value, and I don't know how this could be avoided

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

No branches or pull requests

2 participants