background preloader

Programming

Facebook Twitter

Errors and Debugging in RStudio. Diagnosing and fixing errors in your code can be time-consuming and frustrating.

Errors and Debugging in RStudio

Building a website with pkgdown: a short guide. As promised in my last post, here is a short guide with some tips and tricks for building a documentation website for an R package using pkgdown.

Building a website with pkgdown: a short guide

In the end, this guide ended up way longer than I was expecting, but I hope you’ll find it useful, although it often replicates information already available in pkgdown documentation ! Prerequisites To build a website using pkgdown, all you need to have is an R package hosted on Git Hub, with a file structure “tweaked” with some functionality provided by devtools. Assuming you are using RStudio, and that you didn’t already do this, open the project corresponding to your package and (as a minimum) run: require(devtools)use_readme_rmd()use_news_md()use_vignette("test") #substitute with the name of your package.

Tonsky/FiraCode.

Package creation

Strcode - structure your code better. I am pleased to announce my package strcode, a package that should make structuring code easier.

strcode - structure your code better

You can install it from GitHub, a CRAN submission is planned at a later stage. devtools::install_github("lorenzwalthert/strcode") The main feature of the package is its function to insert code breaks. These are helpful in breaking the code down into smaller sections. We suggest three levels of granularity for code structuring, wherein higher-level blocks can contain lower-level blocks: You can notice from the above that: The number of #’s used in front of the break character (___, ..., . .) correspond to the level of granularity for a code separator. Reading data from google sheets into R. Reading data from google sheets into R is something you imagine should be really simple, but often is anything but.

Reading data from google sheets into R

However, package googlesheets goes a long way to solving this problem. Let’s crack on with an example. First, install the software: install.packages("googlesheets") Tracking progress in R – Bioinformatics Playground. Admit it or not, we human beings become anxious and impatient when it comes to wait.

Tracking progress in R – Bioinformatics Playground

Especially when we are blindfolded — that is, we are unaware of how long we have to suffer the endless wait. As pointed out by Brad Allan Myers, arguably the designer of progress bar in 1980s, being able to track the progress during the waiting can significantly improve the user experience (Myers, 1985). As an R programmer in bioinformatic research, often my codes are not designed for the general public, but it is important to make sure that my users, namely my fellow colleagues and researchers, are as happy as possible.

However, tracking process in R can be tricky. What is the cost of a progress bar in R? – Péter Sólymos. The pbapply R package adds progress bar to vectorized functions, like lapply.

What is the cost of a progress bar in R? – Péter Sólymos

A feature request regarding progress bar for parallel functions has been sitting at the development GitHub repository for a few months. More recently, the author of the pbmcapply package dropped a note about his implementation of forking functionality with progress bar for Unix/Linux computers, which got me thinking. How should we add progress bar to snow type clusters? Which led to more important questions: what is the real cost of the progress bar and how can we reduce overhead on process times? Parallel workflow Fist off, let’s review how a snow type cluster works. How to create a free distributed data collection "app" with R and Google Sheets · Simply Statistics. 26 Aug 2016 By Jeff Leek Share this on → Twitter | Facebook | Google+ Jenny Bryan, developer of the google sheets R package, gave a talk at Use2015 about the package.

How to create a free distributed data collection "app" with R and Google Sheets · Simply Statistics

One of the things that got me most excited about the package was an example she gave in her talk of using the Google Sheets package for data collection at ultimate frisbee tournaments. Profiling with RStudio and profvis. Scheduling R Markdown Reports via Email. R Markdown is an amazing tool that allows you to blend bits of R code with ordinary text and produce well-formatted data analysis reports very quickly.

Scheduling R Markdown Reports via Email

You can export the final report in many formats like HTML, pdf or MS Words which makes it easy to share with others. And of course, you can modify or update it with fresh data very easily. I have recently been using it R Markdown for pulling data from various data source such Google Analytics API and MySQL database, perform several operations on it (merging for example) and present the outputs with tables, visualizations and insights (text). But what about automating the whole report generation and emailing the final report as an attached document every month at a specific time? Programmatically create interactive Powerpoint slides with R. Login - DataJoy - Online Python and R editor. R for Public Health: Basics of Lists. You don’t need icons! Here are 100+ unicode symbols that you can use. Danny Markov Ever needed to add an icon to your design, but you didn’t want to include images or an entire icon font like Font Awesome into your page?

You don’t need icons! Here are 100+ unicode symbols that you can use

We’ve got good news for you – there is a vast library of available icons and glyphs already in your browser. It is called Unicode, and it is a standard which assigns a unique identifier for an ever expanding number (currently over 110 000) of characters, symbols and icons. This doesn’t mean that you have a choice of a hundred thousand icons, though. It is up to the browser to render them, and it uses the fonts which are installed on the system to do so.

Tip: There is a good article which explains everything you need to know about character encodings and unicode, which we recommend for every software developer to read. How to use these icons The icons given in the tables below, are regular characters, which you can copy and paste as if they are letters of text.

Git

REGEX. High performance & Parallel. Using Dates and Times in R. Today at the Davis R Users’ Group, Bonnie Dixon gave a tutorial on the various ways to handle dates and times in R.

Using Dates and Times in R

Bonnie provided this great script which walks through essential classes, functions, and packages. Here it is piped through knitr::spin. The original R script can be found as a gist here. Date/time classes Three date/time classes are built-in in R, Date, POSIXct, and POSIXlt. Date This is the class to use if you have only dates, but no times, in your data. Building email reports with R. Communicating your results Most of the time just writing a bunch of code to analyze data isn't enough, you need to be able to communicate your results to the rest of your company.

This process can take many forms, but we're going to focus on a tried and true method--the automated email. I'll just say upfront that it's your job not to get too carried away. Nobody wants their inbox completely stuffed with your ggplots (no matter how pretty they might be). A brief aside.

Usefull code

Exegetic Analytics. According to Wikipedia, an iterator is “an object that enables a programmer to traverse a container”. A collection of items (stashed in a container) can be thought of as being “iterable” if there is a logical progression from one element to the next (so a list is iterable, while a set is not). An iterator is then an object for moving through the container, one item at a time. Iterators are a fundamental part of contemporary Python programming, where they form the basis for loops, list comprehensions and generator expressions. Iterators facilitate navigation of container classes in the C++ Standard Template Library (STL).

They are also to be found in C#, Java, Scala, Matlab, PHP and Ruby. Although iterators are not part of the native R language, they are implemented in the iterators and itertools packages. The iterators package is written and maintained by Revolution Analytics. Producing Simple Graphs with R. Transforming a color scale. Download all Documents from Google Drive with R.

Getting and Plotting Polls in R. The famous probabilist and statistician Persi Diaconis wrote an article not too long ago about the "Markov chain Monte Carlo (MCMC) Revolution. "