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
- 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.
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 ?? 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 ?? explores how to navigate between different directories, list contents of a directory and create & delete files & directories.
Chapter ?? describes how to create, copy, move, delete and compare files and directories.
Chapter ?? demonstrates how to print text on the terminal and read content from files. It will cover sorting/viewing/searching file contents.
Chapter ?? shows how to search text in file(s) using pattern matching and find files and folders using names and extensions.
Chapter ?? describes how to install, update and remove packages using
Chapter ?? explores how to download files from the internet using
Chapter 8.2.1 demonstrates how to list, extract, create and add files to archives using
Chapter ?? explains how to view system information using
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
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.
The R session information when compiling this book is shown below:
## R version 4.1.0 (2021-05-18) ## Platform: x86_64-w64-mingw32/x64 (64-bit) ## Running under: Windows 10 x64 (build 19042) ## ## Matrix products: default ## ## locale: ##  LC_COLLATE=English_United States.1252 ##  LC_CTYPE=English_United States.1252 ##  LC_MONETARY=English_United States.1252 ##  LC_NUMERIC=C ##  LC_TIME=English_United States.1252 ## ## attached base packages: ##  stats graphics grDevices utils datasets methods base ## ## loaded via a namespace (and not attached): ##  bookdown_0.22 digest_0.6.27 R6_2.5.0 jsonlite_1.7.2 ##  magrittr_2.0.1 evaluate_0.14 highr_0.9 stringi_1.6.2 ##  rlang_0.4.11 rstudioapi_0.13 jquerylib_0.1.4 bslib_0.2.5.1 ##  rmarkdown_2.8 tools_4.1.0 stringr_1.4.0 xfun_0.23 ##  yaml_2.2.1 compiler_4.1.0 htmltools_0.5.1.1 knitr_1.33 ##  sass_0.4.0