Play with the Tribe of Attributes

Functions to make manipulation of object attributes easier. It also contains a few functions that extend the 'dplyr' package for data manipulation, and it provides new pipe operators, including the pipe '%@>%' similar to the 'magrittr' '%>%', but with the additional functionality to enable attributes propagation.


Travis-CI Build Status

Play with the tribe of attributes in R.

Installation

You can install tribe from GitHub with:

# install.packages("devtools")
devtools::install_github("paulponcet/tribe")

Verbs for easy manipulation of attributes

This package provides verbs for easy manipulation of attributes. These verbs are:

  • at_mutate to create or modify attributes;
  • at_select to select attributes (and NULLify the others);
  • at_rename to rename attributes;
  • at_slice to extract attributes.

The function tribe is a convenient synonym of attributes, with the slight difference that it always returns a named list.

library(magrittr)
library(tribe)
 
# Use 'define' to create or modify attributes
df <- data.frame(x = 1:2, y = 2:3) %>%
  at_mutate(example="yes", package="dplyr")
tribe(df)
 
# Use 'at_slice' to extract attribute values
at_slice(df, names)
 
# 'at_slice_' is the standard evaluation version of 'at_slice'
at_slice_(df, "class")
at_slice_(df, ~ package)
 
# Similarly 'at_mutate_' is the standard evaluation version of 'at_mutate'
df <- df %>%
  at_mutate_(package = ~ NULL,
             example = ~ "no")
tribe(df)

A new pipe that preserves attributes

The tribe package provides you with a new pipe %@>% that enables propagation of attributes.

library(dplyr)
library(tribe)
 
df <- data.frame(x = 1:2, y = 2:3) %>%
 at_mutate(example="yes",
           package="tribe", 
           class = c("my_tbl", "data.frame"))
 
# Attributes just created are lost when the object 
# passes through dplyr verbs
tribe(df %>% mutate(z=3))
 
# With the pipe '%@>%', most attributes are kept
tribe(df %@>% mutate(z=3))
 
# One can create a new pipe to adjust attributes propagation settings
"%newpipe>%" <- make_pipe(propagate="none", keep_also = "example")
tribe(df %newpipe>% mutate(z=3))

News

tribe 0.1.7 (2018-02-20)

  • In the infix attribute accessor '%@%', the attribute names can now be passed literally (without quotes).
  • In the verbs for attributes, 'at_xxx()' verbs are kept, while verbs 'define()', 'keep()', 'rebrand()', and 'take()' are removed.

tribe 0.1.6

  • New argument 'try' in 'make_pipe()' to create a new pipe '%try>%'.

tribe 0.1.5

  • New argument 'keep_obj' in 'tribe()'.
  • New function 'untribe()'.

tribe 0.1.4

  • Updated authors in the DESCRIPTION file.

tribe 0.1.3

  • 'stick_to()' and 'unstick()' added.

tribe 0.1.2

  • The pipe '%at>%' is renamed '%@>%'.
  • Dplyr verbs for list manipulations and mutate_which() function are transferred to the 'lplyr' package
  • Infix attribute accessor "%@%" is added (borrowed from package 'purrr')

tribe 0.1.1

  • Minor corrections

tribe 0.1.0

  • Creation of the package 'tribe'

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tribe")

0.1.7 by Paul Poncet, 4 months ago


https://github.com/paulponcet/tribe


Report a bug at https://github.com/paulponcet/tribe/issues


Browse source code at https://github.com/cran/tribe


Authors: Paul Poncet [aut, cre] , Stefan Milton Bache [aut] (for functions copied or modified from the 'magrittr' package) , Hadley Wickham [aut] (for functions copied or modified from the 'magrittr' package)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports bazar, dplyr, lazyeval, magrittr, rlist, rstudioapi

Suggests knitr, ggplot2, lplyr, observer, testthat


See at CRAN