Promoting the use of R in the NHS

Blog Article

This post was originally published on this site

(This article was first published on r-bloggers – STATWORX, and kindly contributed to R-bloggers)

We at STATWORX work a lot with R and we often use the same little helper functions within our projects. These functions ease our daily work life by reducing repetitive code parts or by creating overviews of our projects. At first, there was no plan to make a package, but soon I realised, that it will be much easier to share and improve those functions, if they are within a package. Up till the 24th December I will present one function each day from helfRlein. So, on the 4th day of Christmas my true love gave to me…

What can it do?

This little helper splits a given string into smaller parts with a fixed length. But why? Well I needed this function whilst creating a plot with a long title. The text was too long for one line and instead of just cutting it or let it run over the edges, I wanted to separate it nicely.

day-04-evenstrings

How to use it?

Given a long string like

long_title 

We want to split it after split = "," with a maximum length of char = 60.

short_title 

The function has two possible output formats, which can be chosen by setting newlines = TRUE or FALSE:

  • one string with line separators n
  • a vector with each sub part.

An other use case could be a message that is printed at the console with cat():

cat(long_title)
Contains the months: January, February, March, April, May, June, July, August, September, October, November, December
cat(short_title)
Contains the months: January, February, March, April, May,
 June, July, August, September, October, November, December

Code for plot example

p1 

Overview

To see all the other functions you can either check out our GitHub or you can read about them here.

Have a merry advent season!

Über den Autor

Jakob Gepp

Jakob Gepp

Numbers were always my passion and as a data scientist and statistician at STATWORX I can fullfill my nerdy needs. Also I am responsable for our blog. So if you have any questions or suggestions, just send me an email!

ABOUT US


STATWORX
is a consulting company for data science, statistics, machine learning and artificial intelligence located in Frankfurt, Zurich and Vienna. Sign up for our NEWSLETTER and receive reads and treats from the world of data science and AI. 

Sign Up Now!

Der Beitrag Day 04 – little helper evenstrings erschien zuerst auf STATWORX.

To leave a comment for the author, please follow the link and comment on their blog: r-bloggers – STATWORX.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more…

Comments are closed.