Workflow: Basics

Clear Workspace, DON’T EDIT

Always start by clearing the workspace. This ensure objects created in other files are not used used here.

rm(list = ls())

List Used Packages, EDIT

List all the packages that will be used in chunk below.

packages <- c()

Load Packages, DON’T EDIT

Install Missing

Any missing package will be installed automatically. This ensure smoother execution when run by others.

Installing Packages on Other People Machine

Be aware the people may not like installing packages into their machine automatically. This might break some of their previous code.

# Do NOT modify
install.packages(setdiff(packages, rownames(installed.packages())))
- There are no packages to install.

Load

Load all packages

# Do NOT modify
lapply(packages, require, character.only = TRUE)
list()

9.1 Introduction

This page covers basic concepts when working with R. I took note for those that were new to me or found useful to remind myself with.

9.2 Comments

Use comments to explain the why of your code, eg, you changed the default value of a parameter of a function from say .2 to .9, why?

9.3 Nameing Objects Rules

  • Allowed characters when naming objects
    • letters
    • numbers
    • _
    • .
  • All names must start with a letter
  • R is case-sensitive, ie, var, Var, and VAR are different names