read_microdata: read_microdata loads data from the Grattan Institute data...

View source: R/read_microdata.R

read_microdataR Documentation

read_microdata loads data from the Grattan Institute data warehouse

Description

read_microdata() loads data from the Grattan Institute data warehouse. This function finds the file you're looking for with find_filename() and imports it using rio::import(). Run browseVignettes("grattandata") for more on how to use read_microdata().

This function requires access to the Grattan Institute data warehouse, which is housed in the Grattan Institute Dropbox. If you do not have access to this Dropbox the function will not work. Run check_dropbox_access() if you are unsure if you have access. If you have selective sync enabled in Dropbox (as you should), the file may have to be downloaded before it can be imported, which may take time.

Usage

read_microdata(
  filename,
  fast = FALSE,
  catalog_file = NULL,
  setclass = "tbl",
  write_fst = TRUE,
  ...
)

Arguments

filename

A filename, or fragment of a filename, corresponding to a file in the Grattan data warehouse, such as "SIH15BP.dta". Can include, or not include, the directory name(s). If you specify a file extension, such as ".dta", ".csv", or ".sas7bdat", the extension must match exactly. See examples below for more information.

fast

'FALSE' by default. If set to 'TRUE', 'read_microdata()' will look for a ".fst" version of the file you have requested, and load it if it exists. fst files are a compressed data format that is quick to load. Note that .fst files do not include attributes such as column labels that may be present in Stata and SAS files.

catalog_file

Optional. Filename of SAS catalogue file, including extension. For use with SAS files that store labels in a separate catalogue file. Must be located in the same directory as the data, or a subdirectory of that directory. Will be ignored if 'fast' is 'TRUE'.

setclass

Optional. A character vector specifying the format of the object you wish to import. Default is "tbl", a tibble. Other options are "data.table" and "data.frame". See '?rio::import'.

write_fst

TRUE by default. 'read_microdata()' will look for a .fst file that matches the location and name of the file you've requested. If it doesn't find one, it will create one for future use. Set 'write_fst' to FALSE if you do not want to create an 'fst' file.

...

arguments passed to 'rio::import()'. See '?rio::import'

Details

'read_microdata()' uses the 'find_filename()' function to search the Grattan data warehouse for a file that matches the filename you supply. If no matches are found, it will return an error. If one match is found, it will load the file. If more than one files are found that match your filename, it will tell you what the matches are so you can be more specific.

'read_microdata()' loads files using 'rio::import()'. See '?rio::import' for information on the range of options you can specify, such as the number of lines to skip in a CSV or the range and/or worksheet to import from an Excel workbook.

Examples


# You can import a file by specifying its filename, without the path:
## Not run: 
sih_1516 <- read_microdata("SIH15bp.dta")

## End(Not run)

# You can also include part of the file path if you like:
## Not run: 
sih_1516 <- read_microdata("abs/sih/2015-16/stata/SIH15BP.dta")

## End(Not run)

# If the filename you supply matches multiple files in the data
# warehouse, you'll be told what the matches are so you can be
# more specific.
## Not run: 
sih_1516 <- read_microdata("SIH15BP")

## End(Not run)



grattan/grattandata documentation built on May 10, 2022, 9:33 p.m.