Skip to content

Maintenance - #204

Merged
lorenzwalthert merged 7 commits into
r-lib:masterfrom
lorenzwalthert:maintenance
Sep 20, 2017
Merged

lorenzwalthert merged 7 commits into
r-lib:masterfrom
lorenzwalthert:maintenance

Conversation

@lorenzwalthert

Copy link
Copy Markdown
Collaborator

Some maintenance and infrastructure needed to solve #201 later. Closes #144.

Comment thread R/dplyr.R
rbind.data.frame(x, y)
}

if_else <- function(condition, true, false, missing = NULL) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might just keep if_else(). In dplyr it's a stricter variant of ifelse(), it's just not currently implemented like this but could be.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found it confusing how the function is defined now, because at first look, people may think it's the strict version from dplyr but it's not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dplyr implementation seems to have too many dependencies (in terms of internal functions used) to be dragged over here. But something like:

stopifnot(length(condition) == length(true))
stopifnot(length(condition) == length(false))
if (!is.null(missing)) stop("missing arg not yet implemented")

might just do the job for now.

@lorenzwalthert lorenzwalthert Sep 18, 2017 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the problem is that we deliberately allow for an output that has length zero, e.g. in compute_indent_indices(), so we have used ifelse() all the time in these places. Should we allow for length zero response in "our" implementation of if_else()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

stopifnot(length(true) %in% c(length(condition), 1L))
stopifnot(length(false) %in% c(length(condition), 1L))
if (!is.null(missing)) stop("missing arg not yet implemented")

?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the condition is of length one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we simply use

if (cond) {
  ret <- integer(0)
} else {
  ret <- xyz(fun)
}

For those cases?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dplyr::if_else(TRUE, 1L, integer(0))
#> Error: `false` must be length 1 (length of `condition`), not 0

if_else() is a safety wrapper to ensure that the output length matches the input length. I guess we'll need something different, perhaps a regular if() for other cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Just the way you suggested.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do so.

Comment thread R/dplyr.R Outdated

if_else <- function(condition, true, false, missing = NULL) {
ifelse(condition, true, false)
rbind.data.frame(x, y, ...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point in changing the API here? Do you support more than two arguments? In this case it might be slightly better to forward to bind_rows(rbind.data.frame(x, y), ...) .

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that was the idea.

@lorenzwalthert
lorenzwalthert merged commit e5693a5 into r-lib:master Sep 20, 2017
@lorenzwalthert
lorenzwalthert deleted the maintenance branch September 20, 2017 22:34
krlmlr added a commit that referenced this pull request Oct 23, 2017
- Hotfix: utf8 should not be verbose (#245).
- Allow styling of Rmd files(#233).
- Remove duplicate @family (#244).
- Fixing token insertion (#242).
- Capitalize Addin titles (#241).
- Explicit `NULL` creation to make styler compatible with R3.2.0 (#237).
- Improve vignettes (#232).
- Allow exclusion of files with `style_pkg()` and `style_dir()`.
- Correct styling with long strings (#230).
- Add tools for re-indenting tokens (#217).
- Math token spacing (#221).
- Remove outdated line and col information (#218).
- Empty input for styling does not cause an error (#227, #228).
- Tools to insert tokens + application on `if`-`else` clauses (#212).
- Improve example in documentation (#222).
- Fix spacing around in (#214).
- Maintenance: renaming functions / files, extend helper, documentation, if_else etc. (#204).
- Disallow line break after ( for function calls (#210).
- Preserve space between `!` and bang (#209).
- Simplify RStudio Addin (#208, #211).
- Indention based on square brackets (#207).
- Add vignette on introducing styler (#203).
- Indent function declaration without curly braces correctly (#202).
- Fix indention in if-else statement (#200).
- Sorting key (#196).
- Use safe sequences (#197).
- Fix space between two commas (#195).
- Keep single-line pipes on one line (#74).
- Remove tidyr and dplyr dependency (#182, #183, @jimhester).
- Fix parsing inconsistency (#188).
- Substitute create filler (#190).
- Introducing class vertical (#189).
- Adapt line break rules (#172).
- Fix `R CMD check` (#185).
- Force argument evaluation for proper error handling (#179).
- Add nonstrict version of set_space_before_comment (#174).
- Add installation instructions to README (#175).
- Addin to style highlighted region (#143).
- Improve spelling (#168).
- Add coverage badge
- Change badge from WIP to active
- Add the number of files to message (#166).
- Improve documentation (#164).
- Add informative messages while styling files (#165).
- More examples in help file (#161).
- No line breaks after pipe if comment is next token (#160).
- Fixing spacing around `!` (non-bang-bang) (#157).
- Finalize function documentation (#154).
- Review vignette (#158).
- Update bang-bang rule (#156).
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 this pull request may close these issues.

2 participants