Skip to content

Commit

Permalink
Version 0.6.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
cjendres1 committed Oct 8, 2015
1 parent 3848561 commit 6750eec
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: nhanesA
Version: 0.6.1
Date: 2015-09-30
Date: 2015-10-07
Title: NHANES Data Retrieval
Author: Christopher Endres
Maintainer: Christopher Endres <[email protected]>
Expand All @@ -10,7 +10,7 @@ Description: Utility to retrieve data from the National Health and Nutrition Exa
License: GPL (>= 2)
LazyData: FALSE
URL: https://github.com/cjendres1/nhanes
Packaged: 2015-09-30 18:15:14 UTC; Endres
Packaged: 2015-10-07 18:15:14 UTC; Endres
Suggests: knitr,
rmarkdown
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions INDEX
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Functions:
=========

browseNHANES Browse the NHANES website
nhanes Download an nhanes table
nhanesDisplayTableNames Display names of nhanes tables in a given survey
nhanesDisplayTableVariables Display names of Variables in a given nhanes table
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ importFrom(stringr,str_split)
importFrom(stringr,str_sub)
importFrom(stringr,str_to_title)
importFrom(stringr,str_to_upper)
importFrom(utils,browseURL)
importFrom(utils,object.size)
importFrom(xml2,read_html)
24 changes: 14 additions & 10 deletions R/nhanes.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ data_idx["I"] <- '2015-2016'

anomalytables2005 <- c('CHLMD_DR', 'SSUECD_R', 'HSV_DR')

# An internal function that converts a year into the nhanes interval.
# E.g. 2003 is converted to '2003-2004'
# @param year where year is numeric in yyyy format
# @return The 2-year interval that includes the year, e.g. 2001-2002
#
#------------------------------------------------------------------------------
# An internal function that determines which survey year the table belongs to.
# For most tables the year can be determined by the letter suffix.
get_year_from_nh_table <- function(nh_table) {
if(nh_table %in% anomalytables2005) {return('2005-2006')}
nhloc <- data.frame(stringr::str_locate_all(nh_table, '_'))
Expand All @@ -75,13 +72,17 @@ if(nn!=0){ #Underscores were found
} else {stop('Invalid table name')}
}
return(data_idx[idx])
} else { ## Undersore not 2nd to last. Assume table is from the first set.
} else { ## Underscore not 2nd to last. Assume table is from the first set.
return("1999-2000")}
} else #If there are no underscores then table must be from first survey
nh_year <- "1999-2000"
}
#------------------------------------------------------------------------------

# An internal function that converts a year into the nhanes interval.
# E.g. 2003 is converted to '2003-2004'
# @param year where year is numeric in yyyy format
# @return The 2-year interval that includes the year, e.g. 2001-2002
#
get_nh_survey_years <- function(year) {
if(as.character(year) %in% names(nh_years)) {
return( as.character(nh_years[as.character(year)]) )
Expand Down Expand Up @@ -237,8 +238,8 @@ nhanesTableVars <- function(nh_surveygroup, nh_table, details = FALSE, nchar=100
#' @param nh_table The name of the specific table to retrieve.
#' @return The table is returned as a data frame.
#' @details Downloads a table from the NHANES website in its entirety. NHANES tables
#' are stored in SAS '.XPT' format. Function nhanes uses sasxport.get from package H
#' misc to retrieve the data.
#' are stored in SAS '.XPT' format. Function nhanes uses sasxport.get from package Hmisc
#' to retrieve the data.
#' @examples
#' nhanes('BPX_E')
#' nhanes('FOLATE_F')
Expand Down Expand Up @@ -272,7 +273,7 @@ nhanes <- function(nh_table) {
#' but does not return the table itself.
#'
#' @importFrom Hmisc sasxport.get
#' @importFrom stringr str_c
#' @importFrom stringr str_c str_to_upper
#' @importFrom utils object.size
#' @param nh_table The name of the specific table to retrieve
#' @return The following attributes are returned as a list \cr
Expand All @@ -296,6 +297,7 @@ nhanesAttr <- function(nh_table) {
nh_year <- get_year_from_nh_table(nh_table)
url <- str_c(nhanesURL, nh_year, '/', nh_table, '.XPT', collapse='')
tmp <- sasxport.get(url)
names(tmp) <- str_to_upper(names(tmp))
nhtatt <- attributes(tmp)
nhtatt$row.names <- NULL
nhtatt$nrow <- nrow(tmp)
Expand Down Expand Up @@ -346,6 +348,7 @@ nhanesAttr <- function(nh_table) {
#' @examples
#' nhanesTranslate('DEMO_B', c('DMDBORN','DMDCITZN'))
#' nhanesTranslate('BPX_F', 'BPACSZ', details=TRUE)
#' \donttest{nhanesTranslate('BPX_F', 'BPACSZ', data=nhanes('BPX_F'))}
#' @export
#'
nhanesTranslate <- function(nh_table, colnames, data = NULL, nchar = 32, details=FALSE) {
Expand Down Expand Up @@ -436,6 +439,7 @@ nhanesTranslate <- function(nh_table, colnames, data = NULL, nchar = 32, details
#' The browser may be directed to a specific year, survey, or table.
#'
#' @importFrom stringr str_c str_to_title str_split str_sub str_extract_all
#' @importFrom utils browseURL
#' @param year The year in yyyy format where 1999 <= yyyy <= 2014.
#' @param nh_surveygroup The type of survey (DEMOGRAPHICS, DIETARY, EXAMINATION, LABORATORY, QUESTIONNAIRE).
#' Abbreviated terms may also be used: (DEMO, DIET, EXAM, LAB, Q).
Expand Down
4 changes: 2 additions & 2 deletions man/nhanes.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Use to download NHANES data tables that are in SAS format.
}
\details{
Downloads a table from the NHANES website in its entirety. NHANES tables
are stored in SAS '.XPT' format. Function nhanes uses sasxport.get from package H
misc to retrieve the data.
are stored in SAS '.XPT' format. Function nhanes uses sasxport.get from package Hmisc
to retrieve the data.
}
\examples{
nhanes('BPX_E')
Expand Down
1 change: 1 addition & 0 deletions man/nhanesTranslate.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ values are replaced with the code translations.
\examples{
nhanesTranslate('DEMO_B', c('DMDBORN','DMDCITZN'))
nhanesTranslate('BPX_F', 'BPACSZ', details=TRUE)
\donttest{nhanesTranslate('BPX_F', 'BPACSZ', data=nhanes('BPX_F'))}
}

4 changes: 2 additions & 2 deletions vignettes/Introducing_nhanesA.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: "Introducing_nhanesA"
title: "Introducing nhanesA"
author: "Christopher Endres"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Introducing_nhanesA}
%\VignetteIndexEntry{Introducing nhanesA}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down
8 changes: 4 additions & 4 deletions vignettes/Introducing_nhanesA.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

<meta name="author" content="Christopher Endres" />

<meta name="date" content="2015-10-05" />
<meta name="date" content="2015-10-07" />

<title>Introducing_nhanesA</title>
<title>Introducing nhanesA</title>



Expand Down Expand Up @@ -52,9 +52,9 @@


<div id="header">
<h1 class="title">Introducing_nhanesA</h1>
<h1 class="title">Introducing nhanesA</h1>
<h4 class="author"><em>Christopher Endres</em></h4>
<h4 class="date"><em>2015-10-05</em></h4>
<h4 class="date"><em>2015-10-07</em></h4>
</div>


Expand Down

0 comments on commit 6750eec

Please sign in to comment.