Skip to content

Commit

Permalink
edited README, resized logo, added missing fields to DESCRIPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
nteetor committed Jan 28, 2017
1 parent 079eb89 commit 4fa08f4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 46 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Authors@R: c(
person(given = 'Nathan', family = 'Teetor', email = '[email protected]', role = c('aut', 'cre')),
person(given = 'Paul', family = 'Teetor', role = 'ctb'))
Description: Provides a %<-% operator to perform multiple
or unpacking assignment in R. The operator unpacks a
list of values and assigns these values to a single
or multiple corresponding names.
or unpacking assignment in R. The operator unpacks
the right-hand side of an assignment into multiple
values and assigns these values to variables on the
left-hand side of the assignment.
URL: https://github.com/nteetor/zeallot
BugReports: https://github.com/nteetor/zeallot/issues
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 5.0.1
VignetteBuilder: knitr
Suggests:
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# zeallot 0.0.2.1

* Added missing URL and BugReports fields to DESCRIPTION
* Fixed broken badges in README

# zeallot 0.0.2

* Initial CRAN release
Expand Down
2 changes: 1 addition & 1 deletion R/assignment-op.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' zeallot Assignment Operator
#' Unpacking Operator
#'
#' Assign values to name(s).
#'
Expand Down
87 changes: 50 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
<h1 align="center"> <img alt="zeallot" src="inst/logo.png" height="250"></h1>
<h1 align="center"> <img alt="zeallot" src="inst/logo.png"></h1>

Variable assignment with zeal!

[travis]: https://travis-ci.org/nteetor/zeallot.svg?branch=master "shake and bake"
[appveyor]: https://ci.appveyor.com/api/projects/status/github/nteetor/zeallot?branch=master&svg=true "frappe!"
[coverage]: https://codecov.io/gh/nteetor/zeallot/branch/master/graph/badge.svg "deep fat fry"
[cran]: https://www.r-pkg.org/badges/version/zeallot "getting there"
[cran]: https://www.r-pkg.org/badges/version/zeallot "green means go!"

![alt text][travis] ![alt text][appveyor] ![alt text][coverage] ![alt text][cran]

Below is the zeallot syntax in action.
```R
x: y %<-% c(0, 1)
x
#> 0
y
#> 1
```
---

## What's to be excited about?
## What's there to be excited about?

zeallot allows multiple or unpacking assignment in R. With zeallot you can
tighten code with explicit variable names, unpack pieces of a lengthy list or
the entirety of a small list, de-structure and assign object elements, or do a
little of all of these at once.
the entirety of a small list, de-structure and assign object elements, or do
it all at once.

```R
x: y %<-% c(0, 1)

{r: d} %<-% list(2, 2)

{duration: wait} %<-% faithful

{{a: b}: {c: d}} %<-% list(list(1, 2), list(3, 4))

{first: ...rest} %<-% as.list(letters)
```

You can install zeallot from CRAN,
```R
Expand All @@ -32,9 +37,14 @@ install.packages('zeallot')

## Getting Started

A simple example using the [purrr](https://github.com/hadley/purrr) package.
The `purrr::safely` function returns a "safe" version of a function. From the
safely documentation examples,
Below is a simple example using the [purrr](https://github.com/hadley/purrr)
package and the safely function.

### Safe Functions

The `purrr::safely` function returns a "safe" version of a function. The
following example is borrowed from the safely documentation. In this example a
safe version of the log function is created.

```R
safe_log <- purrr::safely(log)
Expand All @@ -53,18 +63,20 @@ safe_log("a")
#> <simpleError in .f(...): non-numeric argument to mathematical function>
```

A safe function always returns a list of two elements. Instead of throwing an
error, the error element of the return list is set and the value element is
NULL. If no error occurs then the result element is set to the return value of
the original, unsafe, function and the error element is NULL. In either case an
error is not raised.
A safe function always returns a list of two elements and will not throw an
error. Instead of throwing an error, the error element of the return list is set
and the value element is NULL. When called successfully the result element is
set and the error element is NULL.

Safe functions are a great way to write self-documenting code. However, dealing
with a return value that is always a list could prove tedious and may undo
efforts to write concise, readable code. Enter zeallot.

Safe functions are a great way to build flexible, reactive code. However,
dealing with a return value that is always a list could prove tedious. Enter
zeallot.
### The `%<-%` Operator

With zeallot we can unpack our safe function's return value into two explicit
variables and avoid dealing the list return value all together.
With zeallot's unpacking operator `%<-%` we can unpack a safe function's return
value into two explicit variables and avoid dealing with the list return value
all together.

```R
{res: err} %<-% safe_log(10)
Expand All @@ -74,21 +86,22 @@ err
#> NULL
```

zeallot defines the unpacking operator `%<-%`. On the left-hand side of the
operator we create a list of bare variable names using colons and braces. These
variables do not have to be previously defined. On the right-hand side is our
vector, list, or other R objec to unpack.
On the left-hand side of the operator is a list of bare variable names using
colons and braces. These variables do not need to be previously defined. On the
right-hand side is a vector, list, or other R object to unpack. `%<-%` unpacks
the right-hand side, checks the number of variable names against the number of
unpacked values, and then assigns each unpacked value to a variable. The result,
instead of dealing with a list of values there are two distinct variables, `res`
and `err`.

After running the assignment expression on the first example line the `res` and
`err` variables are assigned the result and error values from our safe
function's list return.
### Further Reading

For more on this example, other examples, and a thorough introduction to zeallot
check out the vignette on
[unpacking assignment](vignettes/unpacking-assignment.Rmd).
For more on the above example, other examples, and a thorough introduction to
zeallot check out the vignette on [unpacking
assignment](vignettes/unpacking-assignment.Rmd).

---

Inspiration for this package goes to Paul Teetor.
Thank you to Paul Teetor for inspiring me to build zeallot.

Without his encouragement nothing would have gotten off the ground.
9 changes: 6 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

## R CMD check results

0 errors | 0 warnings | 1 notes
0 errors | 0 warnings | 0 notes

### Notes

* This is a new release.
* Added missing fields to DESCRIPTION
* Fixed broken badges in README
* Minor edits to README, DESCRIPTION, and unpacking-op.Rd
* Package code is unchanged

## Reverse dependencies

This is a new release, so there are no reverse dependencies.
There are no reverse dependencies.

---

Expand Down
Binary file modified inst/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/unpacking-op.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fa08f4

Please sign in to comment.