Coder Social home page Coder Social logo

fmtr's Introduction

fmtr version fmtr lifecycle fmtr downloads fmtr total downloads R-CMD-check Codecov test coverage

Introduction to fmtr

R has a variety of ways to format data. There are functions for formatting dates, several functions to format numbers, plus you can always do a lookup with a named vector, or write your own vectorized function. Yet there are several problems with the way R handles formatting.

One problem is that there are too many formatting functions. It is not easy to remember which functions do what, and the differences between them. One goal of the fmtr package is to consolidate R's formatting capabilities into a smaller number of functions.

Another problem is when you want to reuse a format. While there are many ways to format data, there is no mechanism to save a format and reuse it later. Therefore, another goal of the fmtr package is to promote format reuse.

A third problem is when you have a complex format that can only be accomplished with multiple formatting functions. It would be nice to have a way to keep these multiple formats together, and assign them all at once.

Finally, there are some formatting activities that are so common, it seems like there should be a function for it. The fmtr package also contains several functions that fall into this category.

Solution

The fmtr package was developed to address the above problems. The package addresses those problems in the following ways:

  1. Two formatting functions: With fmtr, all formatting has been consolidated into two formatting functions: fapply() and fdata(). fapply() applies a format to a vector. fdata() applies formats to a data frame or tibble. The implementation of the fapply() function is reminiscent of a SAS® put function.

  2. The format catalog: The fmtr package also introduces the concept of a format catalog to R. A format catalog is a collection of formats that can be saved as a file, shared, and reused. This concept was taken directly from SAS® software.

  3. User-defined format: The fmtr package also improves on the native R formatting capabilities by introducing the concept of a user-defined format. A user-defined format is an expression-driven lookup. You can define a set of logical expressions that, when true, will return a corresponding lookup value. The implementation of the user-defined format is similar to a SAS® user-defined format.

  4. The formatting list: For complicated formats that require more than one function, the fmtr package also introduces the concept of a formatting list. A formatting list can perform operations that are difficult to accomplish otherwise.

  5. Helper and Convenience functions: Finally, the fmtr package contains a set of functions to help you with common formatting tasks. For instance, it has functions to assist in assigning formatting attributes to an entire data frame. It also has some ready-made functions to perform very common types of statistical formatting.

All together, the above capabilities make formatting with the fmtr package both simpler and more powerful. The reuse features also make R more suitable to team programming.

For additional reading, examples, and a complete function reference, refer to the fmtr documentation site here.

Installation

To install the fmtr package, you may do so by running the following command from your R console:

install.packages("fmtr")

Then put the following line at the top of your script:

library(fmtr)

The fmtr package will then be loaded, and available for use in your project.

For examples and usage information, please visit the fmtr documentation site here. These examples will demonstrate the extraordinary usefulness of the formatting functions, and give you many ideas on how and where to use the fmtr package.

Getting Help

If you need help with the fmtr package, the best place to turn to is the fmtr web site. This web site offers many examples, and full documentation on every function.

If you want to look at the code for the fmtr package, visit the github page here.

If you encounter a bug or have a feature request, please submit your issue here

See Also

The fmtr package is part of the sassy meta-package. The sassy meta-package includes several packages that help make R easier for SAS® programmers. You can read more about the sassy package here.

fmtr's People

Contributors

dbosak01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

armenic

fmtr's Issues

Limit rows of printed fcat output

Put some sort of default limit on the printed output of a format catalog. When it is large, it is returning 200+ rows, and is hard to read. Add a parameter to increase rows returned as desired.

Separate format for SD

Add a parameter to the fmt_mean_sd function so that the use can format the standard deviation independently of the mean.

Characters as factors on 3.6

On R 3.6, fdata() function is turning some character columns into factors. This is messing up the reporter package.

Widths issue

Not sure widths attributes are working properly on fdata. Don't seem to be applying to data frame.

Add description attribute

Add description attribute to fattr() function and create descriptions() function to assign all descriptions.

Improve documentation

as.fmt() function is not documented well. Put an example of using that, and creating a format from a data frame.

Import function

Some sort of import function to make it easier to import codelists from a spreadsheet. Would have parameters to map the column names to what is necessary for the format. Returns either a data frame or a finished format catalog.

Possibly add label function

Existing functions to modify label attributes on a data frame are not sufficient. Consider adding a function to do that.

Add description attribute.

Add the description attribute to the set of formatting attributes. This needs to be done because there is no other package that supports a description attribute, and yet it is so commonly needed.

Support old R versions

Add GitHub actions to test with old R versions. Will need a few changes to codes, as this package uses some R 4.0 functions.

Error on assigning fcat to df

When assigning an entire format catalog to a data frame using the formats() function, currently get an error if a variable is missing from the df that exists in the format catalog. Very inconvenient. Make it so that any variables that don't exist are ignored.

Move labels function

Move the labels.data.frame function out of this package and into the common package. Set a dependency on common so that it loads and doesn't break people's code.

Consider blank for sep default on fapply2

The empty string default on fapply2 makes the parameter basically useless. It is easier to put the desired separator in one of the two formats. Would be better to have blank space by default.

CRAN issues

There are some errors from CRAN concerning old version of R to fix. Probably can be fixed just by putting a minimum R version on the package.

Search Path

Possibly add some sort of search path functionality, similar to SAS. So user doesn't have to load the catalog directly.

Bug on as.fmt.data.frame()

There is a bug on as.fmt.data.frame() when converting a non-character label. Need to keep whatever data type is in the data frame.

Date on fdata

When data is read from a SAS dataset and run through fdata, it appears that unformatted data column values are getting changed to the string "DATE". Very odd.

dbf export failing

Need to test dbf import and export. Export is currently failing on a standard data frame. Error is a unrecognized data types.

Print summarized listing for fcat

For the fcat function, change the printing so that it prints a more summarized version of the catalog, basically one line per format. That way the user can see the entire contents of the catalog without anything being cut off.

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.