digIt: digIt() for accessing and importing data

Description Usage Arguments Examples

View source: R/digIt.R

Description

Most example datasets available for statistics and data science are overly simplified. This wrapper provides access to a curated set of more complex data.

Usage

1
digIt(dataset, download = FALSE, readme = FALSE)

Arguments

dataset
download
readme

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (dataset, download = FALSE, readme = FALSE) 
{
    base.path <- "https://s3.amazonaws.com/whoa-data/"
    index.pos <- grep(dataset, digit.cache$dataset)[1] * 1
    if (length(index.pos) == 0) {
        warning("Dataset not found. Look up datasets using digList()")
    }
    else {
        download.zip <- paste0(base.path, digit.cache$zip.package[index.pos])
        download.data <- paste0(base.path, digit.cache$file.name[index.pos])
        download.readme <- paste0(base.path, digit.cache$readme[index.pos])
        load.function <- digit.cache$func[index.pos]
    }
    if (download == TRUE && length(index.pos) > 0) {
        download.file(download.zip, getwd())
        message(paste0(dataset, " has been downloaded to ", getwd()))
    }
    else if (download == FALSE && length(index.pos) > 0) {
        if (load.function == "import") {
            df <- import(download.data)
            message(paste0(dataset, " has been loaded into memory."))
            message(paste0("Dimensions: n = ", nrow(df), ", k = ", 
                ncol(df)))
            if (readme == TRUE) {
                temp.file <- tempfile()
                download.file(download.readme, temp.file, quiet = TRUE)
                file.show(temp.file)
            }
            return(df)
        }
        else if (load.function == "shp" && length(index.pos) > 
            0) {
            if (readme == TRUE) {
                temp.file <- tempfile()
                download.file(download.readme, temp.file, quiet = TRUE)
                file.show(temp.file)
            }
            temp.file <- tempfile()
            download.file(download.zip, temp.file, quiet = TRUE)
            temp.dir <- tempdir()
            unzip(temp.file, exdir = temp.dir)
            shape <- readOGR(dsn = temp.dir, layer = "cb_2016_us_cd115_20m")
            message(paste0(dataset, " has been loaded into memory."))
            return(shape)
        }
    }
  }

SigmaMonstR/digIt documentation built on May 29, 2019, 12:04 p.m.