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

coverage depends on redundant brackets #65

Closed
piccolbo opened this issue Mar 5, 2015 · 2 comments
Closed

coverage depends on redundant brackets #65

piccolbo opened this issue Mar 5, 2015 · 2 comments

Comments

@piccolbo
Copy link

piccolbo commented Mar 5, 2015

You may have mentioned this before but it is quite disturbing that when writing ifs without optional brackets coverage is overestimated. Is this a bug? Thanks

> ff
function(x = T) {
    if(x) {
      1}
    else{
      0}
  }
> cov = function_coverage("ff", ff())
> names(cov) <- paste0("<file>", names(cov))
> cov
Package Coverage: 66.67%
<file>: 66.67%
> ff = 
+   function(x = T) {
+     if(x) 
+       1
+     else
+       0
+   }
> cov = function_coverage("ff", ff())
> names(cov) <- paste0("<file>", names(cov))
> cov
Package Coverage: 100.00%
<file>: 100.00%
@jimhester
Copy link
Member

This is the same as #39. The problem is R considers an if else statement without brackets as one entire expression. There is only one source ref for the entire thing. As source refs are what we use to determine what expressions to track it causes the issue you observed.

We would have to manually break the expression into parts and insert an artificial srcref for each part to fix this.

Considering there exists an easy user side fix (just use brackets) I have not spent time handling this case, but as multiple people have reported it I suppose it needs to be done.

@piccolbo
Copy link
Author

piccolbo commented Mar 6, 2015

got it. I don't think I would call it a fix, it's a workaround. It seems like the fix is complex. Anyhow, closing this as duplicate.

@piccolbo piccolbo closed this as completed Mar 6, 2015
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