background preloader

R

Facebook Twitter

R-Fiddle. OpenCPU. Awesome-R. The SimilaR Project: Similarity of R functions. Blockspring. In this tutorial we'll show you how to add an R function to Blockspring.

Blockspring

Doing so is helpful if you need to: Expose your function to the world. Need some R in your Rails app, Android app, Raspberry Pi, or even in Google Spreadsheets? You'll be able to run your function from any application and device by simply copy/pasting a single line of code. Share your function with anyone. Let's get started! Expose your function to the world. This is going to be insanely fast. SuppressMessages(library('forecast')) URL <- " dat <- read.csv(URL) dat$Date <- as.Date(dat$Date, "%Y-%m-%d") series <- dat[order(dat[,1]),]$Close forecasted_data <- forecast(ts(as.numeric(series)), h=1) forecasted_values <- as.numeric(forecasted_data$mean) print(forecasted_values) Click to populate the Blockspring editor with the code above, click Publish, and you're done! What just happened? Why is this awesome?

Install R in Android, via GNURoot -no root required. # Under GNU-GPL license # R in Android installed via the apps "GNURoot" and "GNURoot Wheezy", and sources.list updated with the newest CRAN repositories. # I strongly recommend to set the working directory of R to a folder that can be accessed from Android such as /sdcard setwd("/sdcard/R") # Just copy and paste the following commands, and press ENTER to see the results.

Install R in Android, via GNURoot -no root required

Hire-an-r-programmer. A list of R conferences and meetings. Using memoise to cache R values. The memoise package can be very handy for caching the results of slow calculations.

Using memoise to cache R values

In interactive work, the slowest calculations can be reading data, so that is demonstrated here. The microbenchmark package shows timing results. Setup First, load the package being tested, and also a benchmarking package. Test conventional function The demonstration will be for reading a CTD file. Search for Key Words or Phrases in Documentation. Description Search for key words or phrases in help pages, vignettes or task views, using the search engine at and view them in a web browser.

Search for Key Words or Phrases in Documentation

Usage RSiteSearch(string, restrict = c("functions", "vignettes", "views"), format = c("normal", "short"), sortby = c("score", "date:late", "date:early", "subject", "subject:descending", "from", "from:descending", "size", "size:descending"), matchesPerPage = 20) Arguments Details This function is designed to work with the search site at and depends on that site continuing to be made available (thanks to Jonathan Baron and the School of Arts and Sciences of the University of Pennsylvania).

Unique partial matches will work for all arguments. Value. FindFn (sos package) FindFn(string, maxPages = 20) Do a search for functions, which opens an interactive HTML page of results.

findFn (sos package)

The results may be sorted in a variety of ways and also link to help files for each function. The results page will automatically open in whatever application has been designated to open .html files (usually a browser is the default). string – A character string to search.maxPages – Maximum number of pages to return, i.e. number of links is 20*maxPages. Example. R-hub builder. Library() vs require() in R. While I was sitting in a conference room at UseR!

library() vs require() in R

2014, I started counting the number of times that require() was used in the presentations, and would rant about it after I counted to ten. Publishing an R package in the Journal of Statistical Software. I’ve been an edi­tor of JSS for the last few years, and as a result I tend to get email from peo­ple ask­ing me about pub­lish­ing papers describ­ing R pack­ages in JSS.

Publishing an R package in the Journal of Statistical Software

So for all those won­der­ing, here are some gen­eral comments. JSS prefers to pub­lish papers about pack­ages where the pack­age is on CRAN and has been there long enough to have matured (i.e., obvi­ous bugs ironed out and a few active users). This is partly because we have so many sub­mis­sions that it helps to fil­ter some out and this approach pro­vides some basic qual­ity checks. So I sug­gest you begin by devel­op­ing the pack­age for CRAN. This is a pref­er­ence rather than a require­ment, and it is not stated any­where in the JSS rules. We pre­fer sub­stan­tial pack­ages rather than very spe­cific but small pack­ages. This paper/​package does what it claims quite well, but it could do so much more. JSS papers involve a review of the soft­ware as well as the paper. Offline install of R package and dependencies. Making R Files Executable (under Windows)

Although it is reasonable that R scripts get opened in edit mode by default, it would be even nicer (once in a while) to run them with a simple double-click.

Making R Files Executable (under Windows)

Well, here we go ... Choosing a new file extension name (.Rexec) First, we have to think about a new file extension name. While double-click to run is a nice-to-have, the default behaviour should not be overwritten. In the Windows universe one cannot simply attach two different behaviours to the same file extension but we can register new extensions and associate custom defaults to those.

Data Import and Export

Data Wrangling. Reproducibility. Learning R. Examples. Plotting. R Apps - Shiny, etc. Cluster Analysis and Strings. Functions.

Testing and Debugging

Control Structures Loops in R. As part of Data Science tutorial Series in my previous post I posted on basic data types in R.

Control Structures Loops in R

I have kept the tutorial very simple so that beginners of R programming may takeoff immediately. Please find the online R editor at the end of the post so that you can execute the code on the page itself. For loops (how to avoid them) My experience when starting out in R was trying to clean and recode data using for() loops, usually with a few if() statements in the loop as well, and finding the whole thing complicated and frustrating.

For loops (how to avoid them)

In this post, I'll go over how you can avoid for() loops for both improving the quality and speed of your programming, as well as your sanity. So here we have our classic dataset called mydata.Rdata (you can download this if you want, link at the right): And if I were in Stata and wanted to create an age group variable, I could just do: gen Agegroup=1replace Agegroup=2 if Age>10 & Age<20replace Agegroup=3 if Age>=20 But when I try this in R, it fails: Why does it fail? Defining Your Own Binary Operators. Loops revisited: How to rethink macros when using R. Data and Code Download All data and code for this blog can be downloaded here: NB: It's been pointed out to me that some images don't show up on IE, so you'll need to switch to Chrome or Firefox if you are using IE.

R loop speed comparison. Recently I had several discussions about using for loops in GNU R and how they compare to *apply family in terms of speed. I have not seen a direct benchmark comparing them so I decided to execute one (warning: some of the code presented today takes long time to execute). First I have started by comparing the speed of assignment operator for lists vs. numeric vectors in standard for loops. Here is the code: The picture showing the result of the comparison is the following: Vectorisation is your best friend: replacing many elements in a character vector. As with any programming language, R allows you to tackle the same problem in many different ways or styles. These styles differ both in the amount of code, readability, and speed. Wonders of foreach. Writing code from scratch to do parallel computations can be rather tricky. However, the packages providing parallel facilities in R make it remarkably easy.

One such package is foreach. I am going to document my trail of discovery with foreach, which began some time ago, but has really come into fruition over the last few weeks. First we need a reproducible example. Preferably something which is numerically intensive. This function generates a square matrix of uniformly distributed random numbers, finds the corresponding (complex) eigenvalues and then selects the eigenvalue with the largest modulus. Since the data are random, each function call yields a different result. It would be interesting to look at the distribution of these results.

Here eigenvalues are calculated from 10000 function calls, all of which use the same parameters. We can make things more interesting by varying the dimensions of the matrix. The results are presented in an intuitive matrix. Choosing R or Python? An infographic. I think you’ll agree with me if I say: It’s HARD to know whether to use Python or R for data analysis. And this is especially true if you’re a newbie data analyst looking for the right language to start with. It turns out that there are many good resources that can help you to figure out the strengths and weaknesses of both languages.

They often go into great detail, and provide a tailored answer to questions such as “What should I use for Machine Learning?” Five ways to handle Big Data in R. Big data was one of the biggest topics on this year’s useR conference in Albacete and it is definitely one of today’s hottest buzzwords. How to speed up R Code: an intro. Getting Started with doParallel and foreach. How-to go parallel in R – basics + tips. Today is a good day to start parallelizing your code. I’ve been using the parallel package since its integration with R (v. 2.14.0) and its much easier than it at first seems. Progress bar in R. Notifications from R. You just sent a long R job running.

Shutdown Windows after Script Has Finished. Test Drive of Parallel Computing with R. Today, I did a test run of parallel computing with snow and multicore packages in R and compared the parallelism with the single-thread lapply() function. In the test code below, a data.frame with 20M rows is simulated in a Ubuntu VM with 8-core CPU and 10-G memory. Snowdoop, Part II. List of useful RStudio addins made by useRs. RStudio addins manager. RStudio addins manager RStudio addins let you execute a bit of R code or a Shiny app through the RStudio IDE, either via the Addins dropdown menu or with a keyboard shortcut.

RStudio add-in to schedule R scripts. With the release of RStudio add-in possibilities, a new area of productivity increase and expected new features for R users has arrived. Thanks to the help of Oliver who has written an RStudio add-in on top of taskscheduleR, scheduling and automating an R script from RStudio is now exactly one click away if you are working on Windows. A Gadget for tidyr. By Aimee Gott About a month ago I wrote a review of the Shiny Developer Conference and I mentioned Shiny Gadgets, my new favourite thing in R. RStudio addin for selecting colours, and another for adding marginal density plots to ggplot2. Citr addin.