Skip to content

Commit

Permalink
add tips, random git stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jtr13 committed Sep 24, 2019
1 parent f7af25a commit 3569bfd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
48 changes: 46 additions & 2 deletions basics.Rmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
output: html_document
---
# R Basics {#basics}

![](images/banners/banner_basics.png)
Expand Down Expand Up @@ -64,6 +67,48 @@ rstudio_latest_version <-
**General advice**: don't get caught up in the details. Keep a list of questions and move on.

## Tips & Tricks

### Knitr

Up your game with chunk options: check out the full [list here](https://yihui.name/knitr/options/){target="_blank"} -- and bookmark it!


### RStudio keyboard shortcuts

- **option-command-i** ("insert R chunk")

```{r, echo = FALSE, comment=""}
cat("```{r}\n```")
```

- **shift-command-M** `%>%` ("the pipe")

### Sizing figures

Always use chunk options to size figures. You can set a default size in the YAML at the beginning of the .Rmd file as so:

```
output:
pdf_document:
fig_height: 3
fig_width: 5
```

Another method is to click the gear `r emo::ji("gear")` next to the Knit button, then **Output Options...**, and finally the **Figures** tab.

Then as needed override one or more defaults in particular chunks:

`{r, fig.width=4, fig.height=2}`


Figure related chunk options include `fig.width`, `fig.height`, `fig.asp`, and `fig.align`; there are [many more](https://yihui.name/knitr/options/#plots){target="_blank"}.

### Viewing plots in plot window

Would you like your plots to appear in the plot window instead of below each chunk in the `.Rmd` file? Click `r emo::ji("gear")` and then **Chunk Output in Console**.


```{r, echo = FALSE, eval = FALSE}
Add this back later:
* **Don't know about Knitr?** Here's [the specific section on Knitr](https://campus.datacamp.com/courses/reporting-with-r-markdown/chapter-two-embedding-code?ex=1){target="_blank"} from the DataCamp course cited above. With this package, you can embed code directly into your R Markdown files and generate output documents. Make sure to go through the later exercises to learn about [code chunks](https://rmarkdown.rstudio.com/lesson-3.html){target="_blank"} and [chunk options](http://yihui.name/knitr/options/){target="_blank"} so you can fine-tune your final output document with ease.
Expand All @@ -73,8 +118,7 @@ Add this back later:
```
### Submitting Assignments
## Submitting Assignments
Here's a quick run-down of how to submit your assignments using [R Markdown and Knitr](#r-markdown-knitr).

Expand Down
16 changes: 16 additions & 0 deletions github_resources.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ Best practices in this area are evolving. My current recommendation is to use th
Another great resource is ["Explore and extend a pull request"](https://happygitwithr.com/pr-extend.html) in *Happy Git with R*. This chapter describes two official GitHub versions of merging a pull request, as well as a workflow in development using `git2r`.
## Random git stuff that may be useful
### Undo the last commit
`git reset --soft HEAD~1`
### Undo changes since the last commit
`git reset HEAD --hard`
### Forgot to branch (didn't commit)

Just create the new branch and changes will be moved there... [changes in the working directory do not belong to a branch until they are committed](https://stackoverflow.com/a/1394804/5314416){target="_blank"} (It will appear that the changes are on master too, but once you commit the changes, they will be gone from master.)



## Other resources

### Getting Help {-}
Expand Down

0 comments on commit 3569bfd

Please sign in to comment.