<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>R on Yoke Keong</title><link>https://yokekeong.com/blog/r/</link><description>Recent content in R on Yoke Keong</description><generator>Hugo</generator><language>en</language><lastBuildDate>Wed, 06 Jul 2016 17:00:50 +0000</lastBuildDate><atom:link href="https://yokekeong.com/blog/r/index.xml" rel="self" type="application/rss+xml"/><item><title>Running Apache Spark with sparklyr and R in Windows</title><link>https://yokekeong.com/running-apache-spark-with-sparklyr-and-r-in-windows/</link><pubDate>Wed, 06 Jul 2016 17:00:50 +0000</pubDate><guid>https://yokekeong.com/running-apache-spark-with-sparklyr-and-r-in-windows/</guid><description>&lt;p&gt;RStudio recently released the &lt;a href="http://spark.rstudio.com/"&gt;sparklyr package&lt;/a&gt; that allows users to connect to Apache Spark instances from R. In addition, this package offers dplyr integration, allowing you to utilize Spark as you use dplyr functions like &lt;code&gt;filter&lt;/code&gt; and &lt;code&gt;select&lt;/code&gt;, which is very convenient. The package will also assist you in downloading and installing Apache Spark if it is a fresh install. This post covers the local install of Apache Spark via sparklyr and RStudio in Windows 10.&lt;/p&gt;</description></item><item><title>Downloading R packages securely</title><link>https://yokekeong.com/downloading-r-packages-securely/</link><pubDate>Tue, 25 Aug 2015 11:00:52 +0000</pubDate><guid>https://yokekeong.com/downloading-r-packages-securely/</guid><description>&lt;p&gt;JJ Allaire from RStudio wrote a &lt;a href="https://support.rstudio.com/hc/en-us/articles/206827897-Secure-Package-Downloads-for-R"&gt;step-by-step guide&lt;/a&gt; on how to configure secured downloads of R packages. Secured downloading of R packages (via HTTPS connection) ensures that you get your packages from legitimate, trusted sources.&lt;/p&gt;</description></item><item><title>Getting session information in R</title><link>https://yokekeong.com/getting-session-information-in-r/</link><pubDate>Tue, 30 Jun 2015 11:00:15 +0000</pubDate><guid>https://yokekeong.com/getting-session-information-in-r/</guid><description>&lt;p&gt;When troubleshooting R bugs or asking for assistance in mailing lists and sites like StackOverflow, it is good to review or present information about your system and packages loaded.&lt;/p&gt;&#10;&lt;p&gt;I much prefer the &lt;code&gt;session_info()&lt;/code&gt; function from the devtools package over the default &lt;code&gt;sessionInfo()&lt;/code&gt; function as it&amp;rsquo;s output is not only more readable, it also provides useful information like timezone and additional packages (non-base) loaded at the time.&lt;/p&gt;&#10;&lt;p&gt;Assuming you have the devtools packages already installed, you can invoke the function in one line:&lt;/p&gt;</description></item><item><title>Updating packages after R upgrade</title><link>https://yokekeong.com/updating-packages-after-r-upgrade/</link><pubDate>Tue, 26 May 2015 11:00:50 +0000</pubDate><guid>https://yokekeong.com/updating-packages-after-r-upgrade/</guid><description>&lt;p&gt;Note to self: After upgrading R (or Revolution R Open) on Windows, run the following command to update the packages at one go.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;update.packages(checkBuilt = TRUE, ask = FALSE)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Drawing map shapes with rgdal</title><link>https://yokekeong.com/drawing-map-shapes-with-rgdal/</link><pubDate>Tue, 05 May 2015 11:00:06 +0000</pubDate><guid>https://yokekeong.com/drawing-map-shapes-with-rgdal/</guid><description>&lt;p&gt;In this post, let us explore the R package rgdal for map shape plotting. We shall attempt to plot the map of Singapore and display major road networks in Singapore.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Pre-requisites&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p&gt;To get the data you need, you can go to a GIS provider. In this post, we shall be using diva-gis.&lt;/p&gt;&#10;&lt;p&gt;Steps:&lt;/p&gt;&#10;&lt;p&gt;1. Go to: &lt;a href="http://www.diva-gis.org/gdata"&gt;http://www.diva-gis.org/gdata&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;2. Select &amp;lsquo;Spatial Data Download&amp;rsquo;&lt;/p&gt;&#10;&lt;p&gt;3. Select Country = &amp;lsquo;Singapore&amp;rsquo;&lt;/p&gt;&#10;&lt;p&gt;4. Select Subject = &amp;lsquo;Administrative areas (GADM)&amp;rsquo;&lt;/p&gt;</description></item><item><title>Reading tabular data with readr package</title><link>https://yokekeong.com/reading-tabular-data-with-readr-package/</link><pubDate>Tue, 14 Apr 2015 11:00:57 +0000</pubDate><guid>https://yokekeong.com/reading-tabular-data-with-readr-package/</guid><description>&lt;p&gt;Recently, Hadley Wickham introduced a new package to read tabular data (such as CSV), lines and entire files.&lt;/p&gt;&#10;&lt;p&gt;Advantages include:&lt;/p&gt;&#10;&lt;p&gt;1. Helpful defaults over base R &lt;code&gt;read.csv&lt;/code&gt; such as: Characters are never automatically converted to factors and row names are never set.&lt;/p&gt;&#10;&lt;p&gt;2. &lt;a href="http://blog.revolutionanalytics.com/2015/04/new-packages-for-reading-data-into-r-fast.html"&gt;Faster reads.&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;3. When reading large files, a progress bar is displayed.&lt;/p&gt;&#10;&lt;p&gt;4. A very useful &lt;code&gt;problems()&lt;/code&gt; function that allows you to zoom into rows of data that readr has issues loading into for e.g. expected integer for this column but actual data is text.&lt;/p&gt;</description></item><item><title>Reading excel files with readxl R package</title><link>https://yokekeong.com/reading-excel-files-with-readxl-r-package/</link><pubDate>Tue, 31 Mar 2015 11:00:05 +0000</pubDate><guid>https://yokekeong.com/reading-excel-files-with-readxl-r-package/</guid><description>&lt;p&gt;Recently, Hadley Wickham introduced a new package to read Excel files (XLS, XLSX). The main advantage is that no external dependencies is required for readxl. (xlsx package requires Java Runtime to be installed)&lt;/p&gt;&#10;&lt;p&gt;With xlsx:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-r" data-lang="r"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;library&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;xlsx&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;2&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;library&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;httr&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;3&lt;/span&gt;&lt;span&gt;url &lt;span style="color:#81a1c1"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;&amp;#34;https://rawgit.com/yoke2/dsxref/master/iris.xlsx&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;4&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;GET&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;url&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;write_disk&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#34;iris.xlsx&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; overwrite&lt;span style="color:#81a1c1"&gt;=&lt;/span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;TRUE&lt;/span&gt;&lt;span style="color:#eceff4"&gt;))&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;5&lt;/span&gt;&lt;span&gt;iris &lt;span style="color:#81a1c1"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;read.xlsx&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#34;iris.xlsx&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; sheetIndex&lt;span style="color:#81a1c1"&gt;=&lt;/span&gt;&lt;span style="color:#b48ead"&gt;1&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; header&lt;span style="color:#81a1c1"&gt;=&lt;/span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;TRUE&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;6&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;head&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;iris&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#b48ead"&gt;3&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;## NA. Sepal.Length Sepal.Width Petal.Length Petal.Width Species&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;2&lt;/span&gt;&lt;span&gt;## 1 1 5.1 3.5 1.4 0.2 setosa&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;3&lt;/span&gt;&lt;span&gt;## 2 2 4.9 3.0 1.4 0.2 setosa&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;4&lt;/span&gt;&lt;span&gt;## 3 3 4.7 3.2 1.3 0.2 setosa&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With readxl:&lt;/p&gt;</description></item><item><title>Download files over HTTPS in R with httr</title><link>https://yokekeong.com/download-files-over-https-in-r-with-httr/</link><pubDate>Tue, 10 Mar 2015 11:00:52 +0000</pubDate><guid>https://yokekeong.com/download-files-over-https-in-r-with-httr/</guid><description>&lt;p&gt;To download a file over HTTP connection, we normally use &lt;code&gt;download.file&lt;/code&gt; command in R, for example:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-r" data-lang="r"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;url &lt;span style="color:#81a1c1"&gt;=&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;&amp;#34;http://vincentarelbundock.github.io/Rdatasets/csv/datasets/iris.csv&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;2&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;download.file&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;url&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;&amp;#34;iris.csv&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; quiet&lt;span style="color:#81a1c1"&gt;=&lt;/span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;TRUE&lt;/span&gt;&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For HTTPS connections, &lt;code&gt;download.file&lt;/code&gt; may give you some issues. In situations like this you can consider using the &lt;a href="http://cran.r-project.org/web/packages/httr/index.html"&gt;httr&lt;/a&gt; package to download files:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-r" data-lang="r"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;library&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;httr&lt;span style="color:#eceff4"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;2&lt;/span&gt;&lt;span&gt;url &lt;span style="color:#81a1c1"&gt;&amp;lt;-&lt;/span&gt; &lt;span style="color:#a3be8c"&gt;&amp;#34;https://rawgit.com/yoke2/dsxref/master/iris.xlsx&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;3&lt;/span&gt;&lt;span&gt;&lt;span style="color:#88c0d0"&gt;GET&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;url&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; &lt;span style="color:#88c0d0"&gt;write_disk&lt;/span&gt;&lt;span style="color:#eceff4"&gt;(&lt;/span&gt;&lt;span style="color:#a3be8c"&gt;&amp;#34;iris.xlsx&amp;#34;&lt;/span&gt;&lt;span style="color:#eceff4"&gt;,&lt;/span&gt; overwrite&lt;span style="color:#81a1c1"&gt;=&lt;/span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;TRUE&lt;/span&gt;&lt;span style="color:#eceff4"&gt;))&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Data Science Learning - A Cross Reference</title><link>https://yokekeong.com/data-science-learning-a-cross-reference/</link><pubDate>Tue, 17 Feb 2015 11:00:12 +0000</pubDate><guid>https://yokekeong.com/data-science-learning-a-cross-reference/</guid><description>&lt;p&gt;While learning data science, I&amp;rsquo;ve discovered that it is very useful to think of the data science processing as a &amp;ldquo;pipeline&amp;rdquo; i.e. a series of actions in a process. Along this pipeline, you will be tackling lots of &amp;ldquo;How do I&amp;hellip;&amp;rdquo; questions like &amp;ldquo;How do I remove NA values?&amp;rdquo; and &amp;ldquo;How do I create N-grams?&amp;rdquo;&lt;/p&gt;&#10;&lt;p&gt;Furthermore, given the many data science tools and languages available online, you will most likely ask the same questions again when you are learning how to perform data science tasks in another language. While Google Search and Stack Overflow/Stack Exchange comes in very handy when searching for answers, I wanted some structure - a collection of sorts - to these questions and have working examples in different language implementations.&lt;/p&gt;</description></item><item><title>A virtual environment for data science</title><link>https://yokekeong.com/a-virtual-environment-for-data-science/</link><pubDate>Tue, 13 Jan 2015 11:00:23 +0000</pubDate><guid>https://yokekeong.com/a-virtual-environment-for-data-science/</guid><description>&lt;p&gt;I wanted to conveniently use data science tools without the hassle of installing the required languages and packages, while benefiting from the strengths of the Linux command line tools. There is a pre-packaged VM called the &lt;a href="http://datasciencetoolbox.org/"&gt;Data Science Toolbox&lt;/a&gt; that fills this need.&lt;/p&gt;&#10;&lt;p&gt;It comes with R and Python installed, along with the respective popular data analysis packages for R and Python. You will be able to install the VM successfully by following the instructions on the &lt;a href="http://datasciencetoolbox.org/"&gt;website&lt;/a&gt;, including installation of pre-requisites like VirtualBox and Vagrant.&lt;/p&gt;</description></item><item><title>Speeding up R</title><link>https://yokekeong.com/speeding-up-r/</link><pubDate>Tue, 16 Dec 2014 11:00:38 +0000</pubDate><guid>https://yokekeong.com/speeding-up-r/</guid><description>&lt;p&gt;When processing large datasets, some R commands operations requiring linear algebra libraries may run very slowly. As such you might want to try &lt;a href="http://mran.revolutionanalytics.com/open/"&gt;Revolution R Open&lt;/a&gt;, an enhanced R distribution using multi-threaded libraries. You can see some benchmarks &lt;a href="http://www.r-bloggers.com/r-r-with-atlas-r-with-openblas-and-revolution-r-open-which-is-fastest/"&gt;here&lt;/a&gt; and &lt;a href="http://blog.revolutionanalytics.com/2014/10/revolution-r-open-mkl.html"&gt;here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Exploring Focal Length with Exiftool and R</title><link>https://yokekeong.com/focal-length-with-exiftool-and-r/</link><pubDate>Thu, 16 Oct 2014 12:00:36 +0000</pubDate><guid>https://yokekeong.com/focal-length-with-exiftool-and-r/</guid><description>&lt;p&gt;&lt;em&gt;Picture Credits:&lt;/em&gt; &lt;a href="https://pixabay.com/vectors/statistic-analytic-diagram-1564428/"&gt;&lt;em&gt;Pixabay&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;A good way to understand your shooting style and guide your future camera equipment buying decisions will be to discover your frequently used focal lengths.&lt;/p&gt;&#10;&lt;p&gt;Focal Lengths can be extract from photos that have EXIF data, which in short refers to data on how these photos are taken. You can find out more from an introductory article &lt;a href="http://photographylife.com/what-is-exif-data"&gt;here&lt;/a&gt;. In this post, we are going to explore focal length usage with the flexible Exiftool and R.&lt;/p&gt;</description></item></channel></rss>