library(powers)

The powers package is an R package with a few functions that can be used as an alternative to the ^ or ** operators.

Below are some example usages of the functions found in this package.

You can easily square or cube numerical data.

square(2)
cube(3.5)
reciprocal(0.5)

The functions in this package can also be used to take vectors of numbers to powers.

square(1:10)
cube(1:10)
reciprocal(1:10)

The functions also work on logical data, coercing it to numerical data.

square(TRUE)
cube(FALSE)
reciprocal(FALSE)

You might be wondering why anyone would use these functions over the basic ^ function. These functions also have a plotting capability! Using the switch plot_it = TRUE any of the powers functions can be made to output a plot of the input vector vs its power (different for every function). You can also output the plot as an object using returnPlot = TRUE. The last input, returnVal = FALSE allows you to supress the raw output of numbers or characters.

For example:

my_plot <- square(1:20, plot_it = TRUE, returnVal = FALSE, returnPlot = TRUE)

To make a plot of any arbitrary power, use the pwr function: For example, taking the 5th power:

my_plot2 <- pwr(1:20, a = 5, plot_it = TRUE, returnVal = FALSE, returnPlot = TRUE)

The powers functions also work on character data! These functions generall works as follows:

pwr("This text should repeat thrice.", a = 3)
pwr("The output of this should be T", a = 0)
pwr("Hello World", a = -3)

That's all there is to it really! I hope this vignette has been informative for you. The library is completely free to use by anyone, just include the license when exporting. Cheers!



HScheiber/powers documentation built on May 22, 2019, 1 p.m.