Assignment 1 Objectives

The purpose of this first assignment is to demonstrate that you have downloaded the “base R” and “RStudio” statistical programs and can open a SPSS datafile in RStudio.

This document was created as an R Markdown file. You will learn about R Markdown files later in the assignment. First, I want to familiarize you with the RStudio interface.

By the end of assignment #1, you should…

  • have created folders on both your personal computer and in cloud storage
  • have 6 full datasets downloaded
  • know how to create R Markdown (RMD) document in RStudio
  • know how to add and modify text, including italic or bold font and level headings, in an R Markdown document
  • know how to add and use an R code chunk in an RMD file
  • know how to use install.packages() and library() commands to install and load packages in R
  • know how to add hashtags (“#”) to comment out a section of R code so it does not run
  • be able to use the “here” package and here() function for simple, reproducible file directory referencing
  • be able to read data into R/RStudio using read_spss() function from “haven” package, then assign it to an object in the R environment using an assignment (<-) operator
  • be able to knit your RMD file into a Word document that you can save and submit for course credit

Assumptions & Ground Rules

For all assignments in this class, you must have access to a computer and Microsoft Word. As a TAMUSA student you have access to the Microsoft 365 suite, which includes 1TB of storage on OneDrive. You may find instructions for how to access and install programs (such as Microsoft Word) from Microsoft 365 in the Resources & Supplemental Texts folder under the Course Content tab in Blackboard.

For this and all future assignments, I will assume you are working on your own computer and are downloading base R and RStudio (free open source) programs on your own computer. If you experience technical difficulties, remember that you can call ITS at 210-784-4357 or email them at for help.

Also, for this and all future assignments, you MUST type all commands in by hand. Do not copy & paste except for troubleshooting purposes (i.e., if you cannot figure out what you mistyped).

Early on, you may have a lot of trouble getting your code to run due to minor typos. This is normal. Remember, you are learning to read and write a new (coding) language. As with learning any new languages, we learn from practice - and from correcting our mistakes.

Part 1 (Assignment 1.1)

Goal: Create new CRIM5305_L_LastName folder on your local computer, then download datasets and save to your new folder (i.e., “L” for “local” computer folder).

(Note: When following instructions, always substitute “LastName” for your own last name! Also, substitute YEAR-MO-DY for the actual date. E.g., 2023-01-27_Ducate_CRIM5305_Assign01)

  1. On your computer, create a new folder called CRIM5305_L_LastName in a location that is easy to access (e.g., on Desktop or in “My Documents”).

  2. Create a new folder in your CRIM5305_L folder called Datasets (CRIM5305_L_LastName > Datasets)
  3. Visit the Companion Website here for Bachman, Paternoster, and Wilson’s Statistics for Criminology & Criminal Justice, 5th Ed (specifically, under the heading: R Data Sets, Full Versions) for the datasets.
    1. Under the header Data Sets for SPSS Full Version, you will see six datasets:
      • Monitoring the Future 2013 grade 10_0.sav
      • NCVS lone offender assaults 1992 to 2013.sav
      • Youth_0.sav
      • 2012 States Data.sav
      • 2013 YRBS.sav
      • GSS 2014.sav
  4. Download each dataset and save them all in the new “CRIM5305_L_LastName > Datasets” folder you made in Part 2.
    • NOTE: To download, you may need to right click and select “Save link as…”

    • Do NOT try to open the datasets after you have downloaded them. If your computer asks which program to open them with, press CANCEL. Do not open them in Microsoft Word. Simply download them. We will open them in RStudio in Part 4.

  1. Take a screenshot (#1) of your new CRIM5305_L_LastName > Datasets folder with all six datasets downloaded in it.
    • PC (Option 1): ctrl + prt sc then ctrl + P into a Word document.
    • PC (Option 2): In the search bar type in “snipping tool” and use the tool to take a snapshot of your Datasets folder.
    • Mac (Option 1): Command + shift + 3; this takes a screenshot of your entire screen and saves on your desktop.
    • Mac (Option 2): Command + shift + 4; this allows you to click and drag to select which part of your desktop you want to screenshot; this also saves on your desktop.

  2. Insert the screenshot into a Word document to your CRIM5305_L_LastName folder. Name the file: YEAR-MO-DY_LastName_CRIM5305_Assign01_folder-screenshot
  3. (Optional) Create a folder titled CRIM5305_C_LastName in your cloud storage (e.g., iCloud, Dropbox, OneDrive).
    • If you have your cloud storage synced to your computer, you can work out of this folder instead of your CRIM5305_L_LastName folder.

    • If you choose to work out of this folder instead of your local folder (which I recommend), be sure to copy your Datasets folder into this folder as well.

Part 2 (Assignment 1.2)

Goal: Download R & R Studio; Open R Markdown; Knit first RMD file

In this section, you will begin by downloading and installing two programs on your computer: base R and RStudio.The first program, R, is simultaneously a computer coding language and a statistical software program. The second, RStudio, is an integrated development environment (IDE) that provides a more user-friendly interface for working with the R program. Throughout this course, you will learn to write and submit R code in RStudio to run statistical commands in the R program. After installing R & RStudio, you will run some simple commands to familiarize yourself with the basic features of the program and install two R packages.

  1. Follow the instructions at the link below to install the latest versions of R and RStudio on your personal Windows or Mac computer: For more detailed instructions, check out Danielle Navarro’s videos for installing R and R Studio in Windows or on a Mac.

  2. Visit Antoine Soetewey’s blog (AS blog) entry at the link below, read the section titled “Main Components of RStudio,” and follow along in RStudio on your computer:

  3. Once you have installed RStudio, open it.
  4. In RStudio, open an “R Markdown” file (File > New File > R Markdown…).
    1. Note: An R Script, which is the default file in RStudio, allows us to write and run code within R. However, an R Markdown file does this as well, while also permitting us to do so much more. For instance, you can write and edit text, write and run R code, and generate statistical results and plots directly in the RMarkdown file. You can even create entire books and webpages using R Markdown. In fact, this assignment was created using R Markdown!
    2. R Markdown is an essential tool for producing reproducible research because, with it, we can thoroughly document and simultaneously provide detailed explanations for all of our coding decisions in a project - from opening and manipulating data, to recoding and combining variables, to summarizing and analyzing data, to creating and modifying figures.
    3. We will start by simply opening and saving a new R Markdown file. For more detailed instructions, check out Danielle Navarro’s video on creating a new R Markdown file.