Drawing map shapes with rgdal

2 min. read 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. Pre-requisites To get the data you need, you can go to a GIS provider. In this post, we shall be using diva-gis. Steps: 1. Go […]

Reading tabular data with readr package

< 1 min. read Recently, Hadley Wickham introduced a new package to read tabular data (such as CSV), lines and entire files. Advantages include: 1. Helpful defaults over base R read.csv such as: Characters are never automatically converted to factors and row names are never set. 2. Faster reads. 3. When reading large files, a progress bar is displayed. […]

Reading excel files with readxl R package

< 1 min. read 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) With xlsx: library(xlsx) library(httr) url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx" GET(url, write_disk("iris.xlsx", overwrite=TRUE)) iris <- read.xlsx("iris.xlsx", sheetIndex=1, header=TRUE) head(iris, 3) ## NA. Sepal.Length Sepal.Width Petal.Length […]

Download files over HTTPS in R with httr

< 1 min. read To download a file over HTTP connection, we normally use download.file command in R, for example: url = "http://vincentarelbundock.github.io/Rdatasets/csv/datasets/iris.csv" download.file(url, "iris.csv", quiet=TRUE) For HTTPS connections, download.file may give you some issues. In situations like this you can consider using the httr package to download files: library(httr) url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx" GET(url, write_disk("iris.xlsx", overwrite=TRUE))