nhanesFromURL function

Download NHANES table from URL

Download NHANES table from URL

Downloads an NHANES table from a URL and returns it as a data frame.

nhanesFromURL( url, translated = TRUE, cleanse_numeric = TRUE, nchar = 128, adjust_timeout = TRUE )

Arguments

  • url: URL of XPT file to be downloaded.
  • translated: logical, whether variable codes should be translated
  • cleanse_numeric: Logical flag. If TRUE, some special codes in numeric variables, such as Refused and Don't know will be converted to NA.
  • nchar: integer, labels are truncated after this
  • adjust_timeout: Typically a logical flag indicating whether the default download.file timeout option should be adjusted by taking into account the size of the file to be downloaded, as reported by the server. The value can also be a positive numeric value, in which case it is used as a further multiplicative factor for the default calculation.

Returns

A data frame containing the data in the XPT file avalable at the URL.

Details

This function downloads a table from the NHANES website using its URL. It is similar to nhanes, except that it requires the URL to be explicitly specified, and does not try to infer it from the table name. It also performs some limited cleansing of the data by default.

The URL may be completely specified, but the initial standard prefix "https://wwwn.cdc.gov" may be optionally dropped. More precisely, if the URL starts with "/nchs/", then the prefix is automatically added. It is possible to override the default prefix by setting the environment variable NHANES_TABLE_BASE (this allows the use of a local or alternative mirror of the CDC data).

Examples

vix_e = nhanesFromURL("https://wwwn.cdc.gov/Nchs/Data/Nhanes/Public/2007/DataFiles/VIX_E.xpt") bpx_e = nhanesFromURL("/Nchs/Data/Nhanes/Public/2007/DataFiles/BPX_E.xpt", translated = FALSE) dim(bpx_e)
  • Maintainer: Christopher Endres
  • License: GPL (>= 2)
  • Last published: 2025-01-10