> For the complete documentation index, see [llms.txt](https://ttezcan.gitbook.io/lectures/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ttezcan.gitbook.io/lectures/all-lectures-and-labs/r-lab/lab-resources/how-to-open-and-use-r-script-files-in-rstudio-cloud.md).

# How to open and use R script files in RStudio Cloud

## <mark style="color:orange;">Video guideline:</mark>

{% embed url="<https://youtu.be/G12HTq6zJ-g>" %}

Make sure you have a RStudio Cloud account. Otherwise, get one and install all the packages. [See this guideline](https://ttezcan.gitbook.io/lectures/all-lectures-and-labs/r-lab/lab-resources/how-to-create-rstudio-cloud-account-and-installing-all-the-packages).

## <mark style="color:orange;">Textual guideline:</mark>&#x20;

1. Open [RStudio Cloud website](https://posit.cloud/) and log in. Click "RStudio labs" under "Your content."
2. Download the R script file you need:
   1. Go to Canvas <mark style="color:red;">➜</mark> Resources module page <mark style="color:red;">➜</mark> “Lab resources” <mark style="color:red;">➜</mark> “All R script files” <mark style="color:red;">➜</mark> Click on the R Script file you need and download that file. [“All script files” is here](https://ttezcan.gitbook.io/lectures/all-lectures-and-labs/r-lab/lab-resources/all-r-script-files) for your convenience.
   2. For example, if you need the "Descriptive Statistics" R script file. Click on it and download:

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2FwzxnaAIcobkFX3PuAJ6Z%2Fss_2024-07-16%2016.55.54.png?alt=media&amp;token=fbdff08a-97a4-4306-ab17-6e005632ce14" alt="" width="375"><figcaption></figcaption></figure>

3. **Uploading R script files 1:** On [RStudio Cloud website](https://posit.cloud/), click “Upload” (see highlighted part #2 below).&#x20;

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2F0baMOH5TRMJWLhNEaVZW%2Fimage.png?alt=media&amp;token=d4260dda-a556-4719-8399-a85b8bbb8f6f" alt=""><figcaption></figcaption></figure>

4. **Uploading R script files 2:** Click “Choose File.” Find the R script file you just downloaded (script\_descriptive.R) in the previous step, click “Open” and "OK."

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2FpC10WDObmNn26ynCMcgC%2Fimage.png?alt=media&amp;token=2d3519e7-04b5-489c-bc0b-881fa6a6d247" alt=""><figcaption></figcaption></figure>

5. **Opening R script files:** The file is uploaded and at the bottom of the "Files" list (see highlighted part #1). When you click on it, the descriptive R script file will open (see highlighted part #2).

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2FBLJecrpSMPuclIeeNh7s%2Fss_2024-07-16%2017.00.10.png?alt=media&amp;token=f163ab11-32a4-49eb-af50-f79529b24198" alt=""><figcaption></figcaption></figure>

6. **Installing and loading packages:** Whenever we open RStudio, we highlight all the lines under the “Install and load packages” (see highlighted part #1) and click run (see highlighted part #2).

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2F7FS3oPGcbCgHmFle1qMu%2Fimage.png?alt=media&amp;token=54f5505c-4409-4828-b934-5c5f5a0f1d0c" alt=""><figcaption></figcaption></figure>

7. **Loading data:** When the process of installing and loading packages is completed, we highlight all the lines under the “Load data” (see highlighted part #1) and click “Run” (see highlighted part #2).  When you see “gss” and “key” (see highlighted part #3), it means we successfully installed and loaded the packages, and loaded the GSS data.

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2F3GWcxVtXggWGa2N6wmKN%2Fimage.png?alt=media&amp;token=f124cdbe-7638-44d2-bf60-b205c743a11d" alt=""><figcaption></figcaption></figure>

8. **Running the analysis codes:** We highlight the codes (see highlighted part #1) and click “Run” (see highlighted part #2). Clicking “Run” generates the analysis (see highlighted part #3).

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2Fr1MUoIScPoLEg3FsgFIn%2Fimage.png?alt=media&amp;token=332a5ef5-9b00-4cba-ba2f-8636f811930c" alt=""><figcaption></figcaption></figure>

9. **Using R script files - “working space” and outline view:** We do not edit or change anything on R script files except under “working space”(see highlighted part #1). Anything above the “working space” is teaching material!<br>

   The codes for assignments will be put under the “working space”<br>

   For easy navigation click “Outline” (see highlighted part #2) to see the headings and subheadings.

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2FBuKmFxmXT40I6lVVpsae%2Fss_2024-07-24%2009.40.36.png?alt=media&amp;token=18434bad-5042-4855-8281-f0ce9bee5548" alt=""><figcaption></figcaption></figure>

10. **Saving R script files:** When we make any changes, the font of the file name (shown in the highlighted part #2 above) will be red with an asterisk (\*) - (see the highlighted part #1 below). To save our progress, we click save (see the highlighted part #2 below)

<figure><img src="https://1373704161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFj6bxTviGJMBga1Kc5Yc%2Fuploads%2FvKnd9VuWetwyqcFA9KyI%2Fss_2024-07-16%2017.06.29.png?alt=media&amp;token=2e3ceb32-482c-4bb6-9cfc-9c3b9343897f" alt=""><figcaption></figcaption></figure>
