R packages

The htmlTable, forestplot, Gmisc, and Greg packages contain useful functions for graphics, tables etc that I’ve created/adapted for my own research. Gmisc was published on CRAN 2014-02-02, and as the htmlTable and forestplot (prev. known as forestplot2) have grown these have moved into separate packages. Some of the regression still needs some more testing before going on CRAN and these are in the Greg-package.

Version 1.0

New htmlTable-package

The htmlTable() has moved as of 1.0 to a separate package in December 2014. The Gmisc will depend on this new package and the change should have minimal impact on user experience. There are plenty of new features and a few API-changes that may be good to be aware of (although the old API will work for 1-2 years only with warnings):

  • rowname -> rnames
  • headings -> header
  • halign -> align.header
  • cgroup.just -> align.cgroup
  • rgroupCSSstyle -> css.rgroup
  • rgroupCSSseparator -> css.rgroup.sep
  • tspannerCSSstyle -> css.tspanner
  • tspannerCSSseparator -> css.tspanner.sep
  • rgroup.padding -> padding.rgroup
  • rowlabel.pos -> pos.rowlabel
  • caption.loc -> pos.caption
  • altcol -> col.rgroup
  • tableCSSclass -> css.table.class

The htmlTable-package is all about generating pretty tables, you can find some examples from my blog-posts below:

New forestplot-package

The forestplot() has moved as of 1.0 to a separate package in December 2014. The Gmisc will have a deprecated call but the link between the package will be removed in the future (2016?). There are plenty of new features and a few API-changes that may be good to be aware of (although the old API will work for 1-2 years only with warnings):

  • legend.* -> legend_args and takes input from fpLegend()
  • confintNormalFn -> fn.ci_norm
  • confintSummaryFn -> fn.ci_sum
  • legendMarkerFn -> fn.legend
  • main -> Title

The package also contains a vignette that you may want to look into:

vignette("forestplot")

Gmisc

The Gmisc package 1.0 was releast in December 2014 on CRAN. Apart from minor API-changes there is the new mergeDesc() that I recommend looking into. Compiling a descriptive table has never been easier.

Greg

The Greg package is still in 1.0 development and may take some time before maturity. You can still download and play around with the new version by specifying the ref="v1.0" as below:

?View Code RSPLUS
1
2
3
4
5
6
# If you haven't installed devtools before, 
# now is the time by uncommenting next line:
# install.packages("devtools")
 
# Install the Greg package using:
devtools::install_github("gforge/Greg", ref="v1.0")

Packages GitHub

As CRAN limits the update frequency to 1-2 months you can download the most recent package from GitHub. You can download them using the devtools package and downloading the develop branch:

?View Code RSPLUS
1
2
3
4
5
6
7
8
9
10
11
12
# If you haven't installed devtools before, 
# now is the time by uncommenting next line:
# install.packages("devtools")
 
# Install the htmlTable package using:
devtools::install_github("gforge/htmlTable", ref="develop")
 
# Install the forestplot package using:
devtools::install_github("gforge/htmlTable", ref="develop")
 
# Install the Gmisc package using:
devtools::install_github("gforge/Gmisc", ref="develop")

Writing documentation is hard and any suggestions are greatly appreciated. Try also to check that the output makes sense as bug-hunting is a difficult and endless task. If you want to suggest some changes, please use the GitHub-version as it has all the roxygen documentation and all my comments.

Some of the neat Gmisc functions that you will find are:

And the Greg-package contains among other things:

  • printCrudeAndAdjusted – a useful function for generating a table with a models crude and adjusted estimates.
  • plotHR – this is based upon r-forge Reinhard Seifert’s plotHR function. The function allows multiple models to be plotted on top of eachother, when used together with transparency (the alpha channel of the rgb) it is very convenient for comparing different subgroups, time-spans or adjusted/unadjusted regressions.

I hope you find the packages as useful as I do. And in case you were wondering – Yes, the Gmisc name is a ripoff from Frank Harrell’s useful Hmisc-package.

Max

flattr this!

11 Responses to R packages

  1. Fr. says:

    Unfortunately, the current installation code does fail on Macs: here’s its output on R 3.0.0.

    • Max Gordon says:

      Hmm… seems to be some issue with the rms-package. Have you tried installing without the dependencies?

      • Fr. says:

        It works if you install “rms” separately:

        install.packages("rms")
        reps = c("http://ftp.sunet.se/pub/lang/CRAN",
                 "http://cran.gforge.se")
        install.packages("Gmisc", repos = reps, dependencies = FALSE, type = "source")

  2. Pingback: Some Results | Shige's Results

  3. Peter says:

    Hi,

    I am currently playing around with your transition plots and I like it very much.

    Features missing I think are options for setting headers and subtitles as well as enabling the user to give all boxes individual texts. I tried the latter in order to also give an information about reaction times in a pre-post-measurement design, but now I get the error:

    Error: could not find function “getGridVal”

    while I have a help file available on that function, it is neither in my workspace after loading Gmisc, nor can I find in your Gmisc github repository.

    What happended here?

    • Max Gordon says:

      The latest version allows for creating your own layout around the plot, just push a grid viewport(), plot using the newpage=FALSE into that viewport. Also, see if you still get the error after setting the newpage=TRUE – there may be some old plot info that causes issues. I’m planning on adding the header option, unfortunately I haven’t had time to implement it yet but you can have a look at the forestplot2() that has the header option working in a similar fashion.

      You can put any text you want in your boxes, I’m currently writing an article on Charnley classification A, B and C before and one year after surgery. In the transitionPlot() call I simply have:

      box_txt=cbind(c("Charnley\nclass\nA", "B", "C\nPre-op."), c("Charnley\nclass\nA", "B", "C\nPost-op."))

  4. Abhinaba Roy says:

    Hi Max,

    I really liked ‘transitionPlot’ function in Gmisc package.
    However I would like to know if we can have a transition plot like
    A >> B >> C

    • Max Gordon says:

      Hi Abhinaba,

      I’ve had this request posted previously but I haven’t had the time to implement it yet. It is not incredibly difficult, but it would require some rethinking. If you want to try to adapt the code you are welcome to write a suggestion for the package. Just fork the Github-repository and write a suggestion. You probably don’t need to get down to the details as the major sections are ready-to-use building blocks. I will try to help you the best I can.

      /Max

  5. Jay Rotella says:

    Thanks for all your great efforts on your packages and tutorials. They’re really helpful. However, when I try to run the last R code chunk, I get an error that reads as below and halts execution:

    Error in missing(xlab) : ‘missing’ can only be used for arguments
    Calls: … withCallingHandlers -> withVisible -> eval -> eval -> forestplotRegrObj
    In addition: Warning message:
    In fix_options(params) :
    You must not set both chunk options out.width and fig.retina

    • Max Gordon says:

      Ok, fixed it. In the version 1.0 I’m trying to make the functions cleaner and I happened to overdo the cleaning. Re-install from Github and see if it works better now.

  6. Aarne says:

    Hi Max,
    this package is simply great and I am more than happy for the possibilities it offers to me to turn our data analysis more reproducible and effective by it.
    However, working on it I have one point. I tried to adapt the script for comparing three groups and just replacing the wilcox.test by the kruskal.test works out perfectly.
    But doing the same with the fisher.test – i.d. replacing it by the chisq.test, brings up the error code:
    Error in getDescriptionStatsBy(parameter, group, :
    could not find function “prDescGetAndValidateDefaultRef”
    Looking through the code I found the call for prDescGetAndValidateDefaultRef (line 119), but I couldn’t find the definition for the function.
    Could you help me?
    Best Wishes Aarne

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>