├── .gitignore ├── LICENSE ├── .Rbuildignore ├── NAMESPACE ├── DESCRIPTION ├── explodeAssign.Rproj ├── R ├── explode-assign.R └── double-explode-assign.R ├── LICENSE.md ├── README.md └── README.Rmd /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | *~ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2022 2 | COPYRIGHT HOLDER: explodeAssign authors 3 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^explodeAssign\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("*") 4 | export("^") 5 | export("|") 6 | export("||") 7 | export(V) 8 | export(VV) 9 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: explodeAssign 2 | Title: Explode Assignment Operators 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | person("Matthew", "Kay", , "mjskay@northwestern.edu", role = c("aut", "cre")) 6 | Description: Provides downwards explode-assignment and double-explode-assignment operators. Do not use them. 7 | License: MIT + file LICENSE 8 | Encoding: UTF-8 9 | Roxygen: list(markdown = TRUE) 10 | RoxygenNote: 7.1.2 11 | -------------------------------------------------------------------------------- /explodeAssign.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /R/explode-assign.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | V = structure(list(), class = "V") 3 | 4 | # have to replace `*` instead of just implementing 5 | # a method to handle cases where x isn't defined yet 6 | #' @export 7 | `*` = function(e1, e2) { 8 | if (inherits(e1, "V")) { 9 | structure(list(x = substitute(e2), env = parent.frame()), class = "V*x") 10 | } else { 11 | base::`*`(e1, e2) 12 | } 13 | } 14 | 15 | #' @export 16 | `|` = function(e1, e2) { 17 | if (inherits(e2, "V*x")) { 18 | invisible(eval(bquote(.(e2$x) <- .(e1)), envir = e2$env)) 19 | } else { 20 | base::`|`(e1, e2) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /R/double-explode-assign.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | VV = structure(list(), class = "VV") 3 | 4 | # have to replace `^` instead of just implementing 5 | # a method to handle cases where x isn't defined yet 6 | #' @export 7 | `^` = function(e1, e2) { 8 | if (inherits(e1, "VV")) { 9 | structure(list(x = substitute(e2), env = parent.frame()), class = "VV**x") 10 | } else { 11 | base::`^`(e1, e2) 12 | } 13 | } 14 | 15 | #' @export 16 | `||` = function(e1, e2) { 17 | if (inherits(e2, "VV**x")) { 18 | invisible(eval(bquote(.(e2$x) <<- .(e1)), envir = e2$env)) 19 | } else { 20 | base::`||`(e1, e2) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2022 explodeAssign authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Explode-assignment operators 5 | 6 | 7 | 8 | 9 | This package provides two alternative assignment operators for R: 10 | 11 | 12 | | || 13 | V VV 14 | * ** 15 | 16 | explode- double- 17 | assign explode- 18 | assign 19 | 20 | Inspired by Matt Dray’s “down-assign” operator (see his 21 | [tweet](https://twitter.com/mattdray/status/1533996890341183488) and 22 | [blog post](https://www.rostrum.blog/2022/06/07/assign-down/)), the 23 | explode-assign and double-explode-assign operators are for when you 24 | *really* want to assign values to variables. 25 | 26 | The main difference between {explodeAssign} and Matt Dray’s proposal is 27 | that {explodeAssign} does not require pre-processing, so all you need to 28 | do is install the package. Like Matt Dray’s proposal, it is also a 29 | terrible idea. 30 | 31 | ## Installation 32 | 33 | You can install the development version of {explodeAssign} like so: 34 | 35 | ``` r 36 | remotes::install_github("mjskay/explodeAssign") 37 | ``` 38 | 39 | This is definitely never going to be on CRAN ;). 40 | 41 | ## Examples 42 | 43 | ``` r 44 | library(explodeAssign) 45 | ``` 46 | 47 | The explode-assignment operator is useful when you emphatically want to 48 | assign a value to a variable by dropping the value into the variable 49 | like a tiny bomb: 50 | 51 | ``` r 52 | # note we need parens. that's okay, safety is important! 53 | ( 54 | 1 55 | | 56 | V 57 | * 58 | x 59 | ) 60 | #> [1] 1 61 | ``` 62 | 63 | `x` now contains the value `1`: 64 | 65 | ``` r 66 | x 67 | #> [1] 1 68 | ``` 69 | 70 | Of course, sometimes we really *really* want to assign a value to a 71 | variable, no matter where it’s hiding (a la `<<-`). Thus the 72 | double-explode-assignment operator: 73 | 74 | ``` r 75 | y = 1 76 | 77 | f = function() { 78 | ( 79 | y + 1 80 | || 81 | VV 82 | ** 83 | y 84 | ) 85 | } 86 | 87 | f() 88 | #> [1] 2 89 | f() 90 | #> [1] 3 91 | f() 92 | #> [1] 4 93 | 94 | y 95 | #> [1] 4 96 | ``` 97 | 98 | ## Note 99 | 100 | {explodeAssign} is not responsible for any mishaps caused by operator 101 | precedence, stray parens, consummate Vs, or overloaded base operators. 102 | Explode-assign at your own risk. 103 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # Explode-assignment operators 17 | 18 | 19 | 20 | 21 | This package provides two alternative assignment operators for R: 22 | 23 | ``` 24 | 25 | | || 26 | V VV 27 | * ** 28 | 29 | explode- double- 30 | assign explode- 31 | assign 32 | 33 | ``` 34 | 35 | Inspired by Matt Dray's "down-assign" operator (see his [tweet](https://twitter.com/mattdray/status/1533996890341183488) and [blog post](https://www.rostrum.blog/2022/06/07/assign-down/)), 36 | the explode-assign and double-explode-assign operators are for when you *really* want to 37 | assign values to variables. 38 | 39 | The main difference between {explodeAssign} and Matt Dray's proposal is 40 | that {explodeAssign} does not require pre-processing, so all you need to do is 41 | install the package. Like Matt Dray's proposal, it is also a terrible idea. 42 | 43 | ## Installation 44 | 45 | You can install the development version of {explodeAssign} like so: 46 | 47 | ``` r 48 | remotes::install_github("mjskay/explodeAssign") 49 | ``` 50 | 51 | This is definitely never going to be on CRAN ;). 52 | 53 | ## Examples 54 | 55 | ```{r setup, message=FALSE} 56 | library(explodeAssign) 57 | ``` 58 | 59 | The explode-assignment operator is useful when you emphatically want to assign 60 | a value to a variable by dropping the value into the variable like a tiny bomb: 61 | 62 | ```{r} 63 | # note we need parens. that's okay, safety is important! 64 | ( 65 | 1 66 | | 67 | V 68 | * 69 | x 70 | ) 71 | ``` 72 | 73 | `x` now contains the value `1`: 74 | 75 | ```{r} 76 | x 77 | ``` 78 | 79 | Of course, sometimes we really *really* want to assign a value to a variable, no matter where 80 | it's hiding (a la `<<-`). Thus the double-explode-assignment operator: 81 | 82 | ```{r} 83 | y = 1 84 | 85 | f = function() { 86 | ( 87 | y + 1 88 | || 89 | VV 90 | ** 91 | y 92 | ) 93 | } 94 | 95 | f() 96 | f() 97 | f() 98 | 99 | y 100 | ``` 101 | 102 | ## Note 103 | 104 | {explodeAssign} is not responsible for any mishaps caused by operator precedence, 105 | stray parens, consummate Vs, or overloaded base operators. Explode-assign at your own risk. 106 | --------------------------------------------------------------------------------