Giter Club home page Giter Club logo

rprintf's Introduction

rprintf

Linux Build Status Windows Build status Coverage Status CRAN Version

rprintf is an adaptive builder for formatted strings. Currently it provides a set of tools for building formatted strings under various replacement rules:

  • C-style formatting with sprintf
  • Number-based formatting
  • Variable-based formatting

The primary goal of this package is to make it easier to produce formatted strings in all popular styles.

Installation

You can install from CRAN with

install.packages("rprintf")

or you can install the latest development version from GitHub with

devtools::install_github("rprintf","renkun-ken")

Examples

The following examples demonstrate how rprintf functions works. You should be familiar with how sprintf works first. See the documentation for more details.

C-style formatting

library(rprintf)
rprintf("Hello, %s", "world")
[1] "Hello, world"
rprintf("%s (%d years old)", "Ken", 24)
[1] "Ken (24 years old)"
rprintf("He is %d but has a height of %.1fcm", 18, 190)
[1] "He is 18 but has a height of 190.0cm"

Number-based formatting

rprintf("Hello, {1}", "world")
[1] "Hello, world"
rprintf("{1} ({2} years old)","Ken",24)
[1] "Ken (24 years old)"
rprintf("He is {1} but has a height of {2:.2f}cm",18,190)
[1] "He is 18 but has a height of 190.00cm"
rprintf("{1}, {2:.1f}, {3:+.2f}, {2}, {1:.0f}",1.56,2.34,3.78)
[1] "1.56, 2.3, +3.78, 2.34, 2"
rprintf("{2},{1}","x","y")
[1] "y,x"

Variable-based formatting

rprintf("Hello, $name", name="world")
[1] "Hello, world"
rprintf("$name ($age years old)",name="Ken",age=24)
[1] "Ken (24 years old)"
rprintf("He is $age but has a height of $height:.2fcm",age=18,height=190)
[1] "He is 18 but has a height of 190.00cm"
rprintf("$a, $b:.1f, $c:+.2f, $b, $a:.0f",a=1.56,b=2.34,c=3.78)
[1] "1.56, 2.3, +3.78, 2.34, 2"

For each type of formatting, a specialized function is also provided. rprintv only handles named variable-based formatting, and rprintn only handles number-based formatting.

License

This package is under MIT License.

rprintf's People

Contributors

renkun-ken avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.