MyNixOS website logo
Description

Mutators that Work with Pipes.

Mutators to set attributes of variables, that work well in a pipe (much like stats::setNames()).

Project Status: Active - The project has reached a stable, usable state and is being actively developed. Build Status Build status

setter: Mutators That Work With Pipes

Mutators to set attributes of variables, that work well in a pipe (much like stats::setNames).

Installation

To install the development version, you first need the devtools package.

install.packages("devtools")

Then you can install the setter package using

library(devtools)
install_bitbucket("richierocks/setter")

Functionality

set_* functions change an attribute, then return their first input, allowing you to chain them together. For example, to turn a vector into a matrix, you could do

m <- 1:12 %>%
  set_dim(3:4) %>%
  set_dimnames(list(letters[1:3], LETTERS[1:4])) 
##   A B C  D
## a 1 4 7 10
## b 2 5 8 11
## c 3 6 9 12

To copy attributes from one variable to another, use a copy_* function.

month.abb %>%
  copy_dim(x) %>%
  copy_dimnames(x)
##   A     B     C     D    
## a "Jan" "Apr" "Jul" "Oct"
## b "Feb" "May" "Aug" "Nov"
## c "Mar" "Jun" "Sep" "Dec"

set_* and copy_* functions are available for the following attributes: names, colnames, rownames, dimnames, class, dim, length.

There are also set_attributes and copy_attributes for setting/copying arbitrary attributes. Here's the previous example thrice more. copy_all_attributes and copy_most_attributes provide a shortcut for copying all the outputs, the latter using base::mostattributes<- to take special care with dim, names and dimnames.

month.abb %>%
  copy_attributes(x, c("dim", "dimnames"))
month.abb %>%
  copy_all_attributes(x) 
month.abb %>%
  copy_most_attributes(x) # special care with dim, names, dimnames
Metadata

Version

0.0-1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows