Preface

In this book, you will be introduced to shell commands. We have selected a set of commands we think will be useful in general to a wide range of audience. We have created a RStudio Cloud Project to ensure that all readers are using the same environment while using code examples. Our goal is to ensure that after reading this book, you should be able to use the shell for version control, managing cloud services (like deploying your own shiny server etc.), execute commands in R & RMarkdown and execute R scripts in the shell. Apart from learning shell commands, the book will also focus on

  • exploring R release names
  • mapping shell commands to R functions
  • RStudio Terminal
  • executing shell commands from R using system2() or processx::run()
  • execute shell commands in RMarkdown
  • execute R scripts in the shell

If you want a deeper understanding of using command line for data science, we suggest you read Data Science at the Command Line. Software Carpentry too has a lesson on shell. We have listed more references at the end of the book for the benefit of the readers.

Outline

We start by introducing what the shell is, how to launch it in different operating system and explore commands for navigating file system and file management.

  • Chapter 1 introduces the shell. It shows how to launch it in different operating systems. Apart from introducing the RStudio terminal, it will explore basic commands and different ways to view the documentation.

  • Chapter 2 explores how to navigate between different directories, list contents of a directory and create & delete files & directories.

  • Chapter 3 describes how to create, copy, move, delete and compare files and directories.

  • Chapter 4 demonstrates how to print text on the terminal and read content from files. It will cover sorting/viewing/searching file contents.

  • Chapter 5 shows how to search text in file(s) using pattern matching and find files and folders using names and extensions.

  • Chapter 7 describes how to install, update and remove packages using sudo.

  • Chapter 6 explores how to download files from the internet using wget and curl.

  • Chapter 8 demonstrates how to list, extract, create and add files to archives using tar, zip and unzip.

  • Chapter 9 explains how to view system information using uname, free, df etc.

  • Chapter 9.2 demonstrates how to execute shell commands in R using system2(). It will also look at using shell commands in RMarkdown documents and how to execute R commands and scripts from the command line.

Topics this book does not cover

While the book explores several shell commands and demonstrates how to execute them in R, it does not cover the following topics:

  • shell scripting
  • editing files
  • file permissions
  • user information
  • pipes
  • awk
  • sed

About this book

This book is focused on practical exploration of shell commands. We focus on a select set of commands we hope will be useful to beginners and motivate them to explore the command line further.

We do not assume any previous knowledge of command line. We have used the RStudio terminal and RStudio Cloud to remove any hurdles for beginners and to ensure all learners have access to the same environment to explore the commands.

We do assume the reader is familiar with R and RStudio.

Using code examples

All the codes used in this book are available in our GitHub repository. We encourage you to use RStudio Cloud (it is free), especially Windows users as you will get access to Linux Bash and all the code and files/directories used in the examples.

Software information

The R session information when compiling this book is shown below:

## R version 3.6.1 (2019-07-05)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18362)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_India.1252  LC_CTYPE=English_India.1252   
## [3] LC_MONETARY=English_India.1252 LC_NUMERIC=C                  
## [5] LC_TIME=English_India.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] compiler_3.6.1  magrittr_1.5    bookdown_0.13   tools_3.6.1    
##  [5] htmltools_0.3.6 rstudioapi_0.10 yaml_2.2.0      Rcpp_1.0.2     
##  [9] stringi_1.4.3   rmarkdown_1.15  knitr_1.24      stringr_1.4.0  
## [13] xfun_0.9        digest_0.6.21   evaluate_0.13