# Network Package
install.packages("igraph")
library(igraph)
# Package to access data
# Make sure you have remotes installed first
install.packages("remotes")
::install_github("Tom-R-Leppard/ADAPTSNA")
remoteslibrary(ADAPTSNA)
2 Getting Started with R
2.1 Quick Start
If you are an old hand when it comes to coding and have experience with R, great! Know that we will mostly be using the package ‘igraph’ so go ahead and install it now (you can use the code below). Keep an eye out for the new packages we use throughout the book and install them as you go.
The data we will be using come from the “ADAPTSNA” package which is the companion package to this book and available on my Github. Install it using the code below.
Other than that, get going!
2.2 New to R?
If you are new to R or new to coding, wonderful! This is a great way to start getting into it. There are a few steps we need to take before you install the package above. If you are planning on using R long term, I strongly suggest downloading it and RStudio to your personal machine. Even if you don’t I suggest doing this because it is the most straightforward (go to option 1). If not, say you don’t have a personal machine and need to use a public machine or one in a lab, then there are ways to work with that (go to option 2).
2.3 Option 1: Downloading R/RStudio
To get going, you will need to download both R and RStudio. Yes, these are separate downloads. Think of R as the engine, and Rstudio as the car you are driving. RStudio makes it easy to do the things you want to do while R, (the ‘engine’) actually drives everything you do. To do this, follow the instructions on the Posit website. At the time of the publication of this book, this link has 2 steps, one to install R and the other to install RStudio. Depending on your machine (if you have a windows, mac or an operating system like Linux) there are different instructions. Download and install the the ones you need.
2.4 Option 2: Posit Cloud
If you do not want to or cannot download R/RStudio, there are a few ways to use it for free, albeit limited, online. Consider making a free account on Posit Cloud.
Once you have made your account, click on the tab at the top right to create a new project. Select RStudio. From here on its mostly the same with a few tweaks, pay attention below for a few differences between posit cloud and downloading RStudio.
2.5 A little about RStudio
Once you have installed it, or created your new project on Posit Cloud, go ahead and open RStudio. When you open RStudio, you will see four windows, let’s walk through those for a moment. There are multiple uses for each window. However, for now, we will discuss them how we will be using them just to get you started.
Starting from the top left, you have a window for your script files. Think of this as a place to write, run, and store code. Here, you can open different files including script, markdown, quarto and others. For the sake of what we are doing in this book, just focus on those three types.
On the bottom left there is a space for you to enter code and run it directly. This is basically a window to look at the engine.
Next, the top right window houses your global environment. Think of this as a bucket. What you do in the script or the console can fill things into the bucket. For example, you can bring in network data and store it in this environment.
Finally, on the bottom right there are multiple reasons we use this window. Mostly, the network visualisations we will create will appear in the ‘Plots’ or ‘Viewer’ tab.
2.5.1 On Packages
Another thing you need to know is that we will be using multiple types of commands throughout this book. These are grouped into what are called ‘packages.’ Think of packages as mini dictionaries for different languages. In this case, however, these languages enable you to do different things with/to your data.
To access these packages, you first need to install them. You can do this, using the following function.
install.packages("igraph")
The above code will download the package to your machine (or your project space on posit.cloud). Then, you need to tell R which “language” you are coding in each time you open up RStudio. To do this, you use the ‘library()’ function. Keep an eye out for the various packages use. If you see a command to bring in a package you don’t recognise, you will need to install it (just replace igraph with the name of the other package in the above chunk).
library(igraph)
You only ever need to install it once on to your machine but every time you open R you will need to activate it in your library.
2.5.2 Loading Data
Great stuff! You now have RStudio sorted out and you (if you ran the above) have installed igraph. Now, the last thing you need is the data that you are going to use and to bring it into the environment. There are many ways that you can do this, but I have provided you, what I think, is the simplest low-tech method that you can use across both on posit cloud or your own machine.
In each of the chapters, you will need both the “igraph” and “ADAPTSNA” packages. “igraph” is the network package, “ADAPTSNA” is a package to help you bring in the data used in this book. Follow the code below to install the second package.
# Package to access data
# Make sure you have remotes installed first
install.packages("remotes")
::install_github("Tom-R-Leppard/ADAPTSNA")
remoteslibrary(ADAPTSNA)
This package has all of the datasets we will be using for this book. To see all of the available datasets in this package, use the code below. This will return the names of the .csv files we are using.
list_data_files()
The only thing left to do, is to head over to the Github repo and get started thinking about your project!