Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ several options on how to participate (below).

github
vscode
rstudio
editors
git-in-terminal
ssh
Expand Down
18 changes: 18 additions & 0 deletions content/rstudio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(rstudio)=

# RStudio

[RStudio](https://posit.co/products/open-source/rstudio) is a popular coding environment for R. It is **free and open source** and runs on your desktop and is
available for Windows, macOS, and Linux.
**If you are an R user and already use RStudio, we recommend to start with this one**.

- To install RStudio, please visit the [download page](https://posit.co/downloads/) for
installation instructions. No specific settings are needed during installation to use Git.

To set up RStudio with Git:

- First, follow the first section of [Git in terminal](https://coderefinery.github.io/installation/git-in-terminal/)
on [Installation](https://coderefinery.github.io/installation/git-in-terminal/#installation) to make sure Git is installed on your computer.

- Then, proceed to [SSH or HTTPS connection to GitHub from terminal](https://coderefinery.github.io/installation/ssh/)
and follow the RStudio tabs.
100 changes: 98 additions & 2 deletions content/ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ If you use VS Code, authentication to GitHub happens automatically via
if you use **HTTPS**.
````

````{group-tab} RStudio
**If you use RStudio**

If you use RStudio, authentication can happen either via HTTPS or SSH. Here, the RStudio instructions cover using **HTTPS**.

````

`````

You should remember your choce for the lessons.
You should remember your choice for the lessons.



Expand Down Expand Up @@ -119,6 +126,53 @@ No further setup is needed. VS Code prompts you to automatically
handles the authentication when needed.
````

````{group-tab} RStudio

First, install the R package `usethis` if it isn't already installed:

```r
install.packages("usethis")
```

Next, we set a user name and email to be used with Git by running this command in R:

```r
usethis::use_git_config(user.name = "Firstname Lastname", user.email = "name@organization.org")
```

If you are unsure which email to use, use the one that you have registered at
GitHub with.

**This name and email will be public on GitHub when you make
contributions, including in this course.** If you prefer to not use a real email address but still want to make sure that
GitHub counts your contributions, you can use
`yourusername@users.noreply.github.com` (replace `yourusername`). This is important since your Git commits use this information.


Then, let's create a Github token for HTTPS:

```r
usethis::create_github_token()
```

This will open a Github web page. Give the token a name, for example related to the project you are working on,
and set the expiration date as you wish. In the section for scopes, the defaults are OK in most cases.
Generate the token. **Important: save the generated token on the clipboard or in a file, or keep the web page open.** The token can't be retrieved later and will be needed in the next step.

To give the token to RStudio, run in R:

```r
gitcreds::gitcreds_set()
```

Paste the token when prompted. Now you are ready to use Git with RStudio.

If the token expires or gets lost, create a new one the same way.

*Reference and more details on connecting RStudio, Git and Github: [Happy Git and Github for the useR](https://happygitwithr.com/)*

````

`````


Expand Down Expand Up @@ -208,7 +262,7 @@ it on a repository you have access to.
class: dropdown
---
If you are on a remote server and Git can't automatically start a web
browwser, you might get this prompt:
browser, you might get this prompt:

```
Select an authentication method for 'https://github.com/':
Expand All @@ -221,5 +275,47 @@ Select option 1 and do what it says.
`````
`````{group-tab} VS Code
No further checking is needed (we hope).
`````

`````{group-tab} RStudio

In the RStudio console panel, click the Terminal tab.

Run the following command:

````console
$ git clone https://github.com/rkdarst/private-example.git
````

This is private so **it will say the repository is not found, but
that's OK.** This is what the output looks like if **the
authentication was successful:**

````{code-block} console
---
emphasize-lines: 3
---

$ git clone https://github.com/rkdarst/private-example.git
Cloning into 'private-example'...
remote: Repository not found.
fatal: repository 'https://github.com/rkdarst/private-example.git/' not found
````

If authentification was not successful, you will see this:

````{code-block} console
---
emphasize-lines: 3
---
git clone https://github.com/rkdarst/private-example.git
Cloning into 'private-example'...
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/rkdarst/private-example.git/'
````

In this case, go back to the previous step and make sure you have created a token and
passed it to RStudio.

`````
``````