+ "text": "2.4 Installation Process\nIn this section, I will provide you with links to set up various programs on your own machine. If you have trouble with these instructions or encounter an error, post on the class message board or contact me for help.\n\nInstall R (and associated tools)\n\n\n\n Windows\n Mac\n Linux\n\n\n\n\nGet the R installer from CRAN: https://cran.rstudio.com/bin/windows/base/\nInstall the Rtools4 package that matches the R version you installed: https://cran.rstudio.com/bin/windows/Rtools/\nFor example, if you installed R 4.4.3, you should download RTools 4.4. If you installed R 4.0.1, you should install RTools 4.0.\n\n\n\n\nGet the R installer from CRAN: https://cran.rstudio.com/bin/macosx/\nInstall XCode - a set of developer tools - so that you can install R packages more easily. There are two ways to do this:\n\n\nGet XCode from the App store directly (simple, but you may have to do other things later)\nInstall Homebrew and then use homebrew to install XCode.1\n\n\nI personally suggest option b, because Homebrew is used for a lot of different software-development related things, and having it will make life easier later.\nInstalling Homebrew + XCode\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"\nbrew install mas # Search the apple store\nmas search xcode # find xcode\nmas install 497799835 # install the program by ID\n\n\n\nIf you’re using a distribution like Debian, Fedora, RedHat, or Ubuntu, or a distribution derived from one of these distributions, follow the instructions below.\nIf you don’t know your distribution (or if you’re working on a derivative distribution, like Mint), you can figure out which set of instructions to follow by executing lsb_release -a in your system terminal.\nIf you’re using Arch or another distribution that isn’t derived from something listed above, google for instructions specific to your distribution - these instructions cover the most common, user-friendly distributions, but if you’ve chosen something more niche, it is assumed you can figure out how to install R. (If that isn’t the case, leave a comment below with your distribution, so I know how best to update this book.)\n\nInstallation Instructions\n\nGet the R installer from CRAN: https://cran.rstudio.com/bin/linux/ - pick your distribution, and follow the distribution-specific instructions from there.\n\nYou could install R using your package manager, but often this version is out of date. The instructions for each version will get you a more up-to-date version that will be easier to work with.\n\n\n\n\n\n\nDownload and install the latest version of python 3\n\n Windows: check the box that asks if you want to add Python to the system path. This will save you a lot of time and frustration. If you didn’t do this, you can follow these instructions to fix the issue (you’ll need to restart your machine).\nIf you’re interested in python, you should install Jupyter using the instructions here (I would just do pip3 install jupyterlab)\nWe will not use jupyter much in this book - I prefer quarto - but the python community has decided to distribute code primarily in jupyter notebooks, so having it on your machine may be useful so that you can run other people’s code.\nAdditional instructions for installing Python 3 from Python for Everybody if you have trouble.\n\n\nDownload and install the latest version of RStudio for your operating system. RStudio is a integrated development environment (IDE) for R, created by Posit. It contains a set of tools designed to make writing R, python, javascript, and other data-related code easier.\nDownload and install the latest version of Quarto for your operating system. Quarto is a command-line tool released by Posit that allows you to create documents using R or python, combining code, results, and written text.\n\nThe following steps may be necessary depending on which class you’re in. If you want to be safe, go ahead and complete these steps as well.\n\n\nInstall git using the instructions here. Consult the troubleshooting guide if you have issues. If that fails, then seek help in office hours.\nWe will configure git later, in Chapter 5. For now, let’s just get it installed.\n\n\nInstall LaTeX, rmarkdown, and quarto:\n\nLaunch R, and type the following commands into the console:\n\n\ninstall.packages(c(\"tinytex\", \"knitr\", \"rmarkdown\", \"quarto\"))\nlibrary(tinytex)\ninstall_tinytex()\n\nIf you have an existing installation of LaTeX, using tinytex or another installer, I highly recommend that you uninstall LaTeX before re-installing the most recent version.\n\nConfigure RStudio to use the tinytex installation of LaTeX:\n\nGo to Tools -> Global Options -> Sweave\n\n\n\n\n\n\n\n\n\n\n\n\nYour turn\n\n\n\nOpen RStudio on your computer and explore a bit.\n\nCan you find the R console? Type in 2+2 to make sure the result is 4.\nRun the following code in the R console to set up some basic packages:\n\ninstall.packages(c(\"tidyverse\", \"rmarkdown\", \"knitr\", \"quarto\"))\n\nRun the following code in the R console to set up Python:\n\ninstall.packages(\"reticulate\")\nreticulate::virtualenv_create(\"stat-python\") # Create a python environment\nreticulate::virtualenv_install(\"stat-python\", c(\"numpy\", \"matplotlib\", \"pandas\"))\n\nConfigure RStudio to use the python virtual environment you created:\n\nGo to Tools -> Global Options -> Python\nClick the Python interpreter Select button\nClick Virtual Environments\nChoose stat-python and hit “Select”\nRestart RStudio when prompted to ensure the setting takes effect.\n\n\nTest out Python:\n\nGo to the Console tab, and click on the R logo. A dropdown should be present with an option to select Python.\nWait for the Python prompt to appear (it will look like this: >>>)\nType 2 + 2, hit enter, and make sure the result is 4.\n\n\nCan you find the text editor?\n\nCreate a new quarto document (File -> New File -> Quarto Document).\nSelect a blank quarto document (bottom of the pop-up window)\nChange the text editor to Source mode (it will default to visual mode). This makes it possible to paste a quarto document without Visual mode trying to “fix” the markup characters.\nPaste in the contents of this document.\nCompile the document (Ctrl/Cmd + Shift + K) and use the Viewer pane to see the result.\n\n\nIf this all worked, you have RStudio, Quarto, R, and Python set up correctly on your machine.",
0 commit comments