saving_yrbs_locally.Rmd
Welcome to dissertationData! This package provides easy access to data from the Youth Risk Behavior Survey (YRBS), a critical resource for studying adolescent health trends.
Whether you’re an experienced analyst or just starting, this guide will walk you through how to load, and save YRBS data efficiently.
If you haven’t installed the package yet, you can install it from GitHub:
# Install from GitHub:
# install.packages("devtools")
# devtools::install_github("yourusername/dissertationData")
Once installed, load the package:
library(dissertationData)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#> Loading required package: stringr
#> Loading required package: tidyr
#> Loading required package: ggplot2
There are times when you might want to store a local copy of the raw data for your own use. This package allows you to save the data in multiple formats, including CSV, SPSS (.dat), and Parquet, so you can choose the format that works best for you.
Many users prefer to save data in CSV format. This
package provides a dedicated function that allows you to save the
dataset as a CSV file while automatically creating a folder called
"data"
to store it.
This function allows you to save any dataset available in the package as a CSV file. To check the available datasets, use:
list_package_datasets("dissertationData")
#> [1] "clean_yrbs_2017" "clean_yrbs_2019"
#> [3] "clean_yrbs_2021" "clean_yrbs_2023"
#> [5] "combinedYRBS" "combined_dictionary"
#> [7] "dictionary_2015" "dictionary_2017"
#> [9] "dictionary_2019" "dictionary_2021"
#> [11] "dictionary_2023" "dissertation_data"
#> [13] "raw2015" "raw2017"
#> [15] "raw2019" "raw2021"
#> [17] "raw2023" "suicide_related_variables"
To save the raw 2015 dataset as a CSV file, use the following example:
# Save the data in a csv form
save_data_to_csv("raw2015")
After running this command, the dataset will be saved in your local machine, and the file path will be displayed in the console. For example:
Dataset saved successfully at: /Users/myuser/myfolder/data/raw2015.csv
If you only need the raw version of the YRBS dataset in a format other than CSV, we have designed a function that gives you full control over:
The function is called get_raw_data()
, and you can
specify the storage folder using the dest_dir
parameter.
For example, to save the 2017 dataset in a folder
named "my_data"
, run:
# Copy the YRBS 2017 SPSS file to a folder called "my_data"
save_raw_data(2017, format = "spss", dest_dir = "my_data")
If the specified folder does not exist, the function will ask
for your permission to create it.
Once confirmed, it will generate the folder and provide the file’s
location.
For example, if you specify "my_data"
as the storage
folder but it doesn’t exist, you’ll see:
Would you like to proceed with creating '{dest_dir}'? (y/n): y
✔ Directory 'my_data' created.
✔ File copied to my_data/yrbs2017.sav
In this vignette we covered:
The goal of dissertationData is to simplify the process of accessing and working with YRBS data. We hope this guide helps you get started quickly and confidently.
If you have any questions or run into issues, please refer to the package documentation or contact the package maintainer.
Happy analyzing!