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

Use %||% to replace if (is.null(x)) {do else} pattern #630

Closed
njtierney opened this issue May 22, 2024 · 0 comments
Closed

Use %||% to replace if (is.null(x)) {do else} pattern #630

njtierney opened this issue May 22, 2024 · 0 comments
Labels
low hanging fruit Issue is simple to implement. TF2-resolved Up Next
Milestone

Comments

@njtierney
Copy link
Collaborator

E.g.,

if (is.null(dim)) {
        dim <- c(1, 1)
      }

# ...

# store array (updates dim)
      if (is.null(value)) {
        value <- unknowns(dim = dim)
      }

would be

dim <- dim %||% c(1,1)

# store array (updates dim)
value <- value %||% unknowns(dim = dim)

%||% is available in R 4.4.0, or can be re-exported from rlang or implemented locally easily enough.

@njtierney njtierney added this to the 0.6.0 milestone May 22, 2024
@njtierney njtierney added Up Next low hanging fruit Issue is simple to implement. labels Jul 24, 2024
@njtierney njtierney modified the milestones: 0.6.0, 0.5.0 Jul 25, 2024
njtierney added a commit to njtierney/greta that referenced this issue Jul 25, 2024
That is, replace:

```r
if (is.null(x)) x <- thing
```

with

```r
x <- x %||% thing
```
@njtierney njtierney modified the milestones: 0.5.0, 0.6.0 Jul 25, 2024
@njtierney njtierney moved this from Backlog to Done in {greta} CRAN 0.5.0 release Jul 29, 2024
@njtierney njtierney closed this as completed by moving to Done in {greta} CRAN 0.5.0 release Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low hanging fruit Issue is simple to implement. TF2-resolved Up Next
Projects
No open projects
Development

No branches or pull requests

1 participant