Skip to content

Commit 90695eb

Browse files
committed
Add a bit of content... Just some friendly notes.
1 parent b616aab commit 90695eb

8 files changed

+169
-51
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ vignettes/*.pdf
3737

3838
# R Environment Variables
3939
.Renviron
40+
41+
/.quarto/
42+
43+
/.luarc.json
44+
45+
*_book/

README.md

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# quarto-book-template
2-
Template repository for creating a book powered by Quarto and Rendered by GitHub Actions onto GitHub Pages
1+
# r-reference
2+
3+
The repository holds a reference book of _R_ related programming topics and ideas. This primarily serves as a way for the author to quickly catalog and store code snippets in the vein of a personal knowledge management (PKM).
34

45
## Overview
56

@@ -8,27 +9,6 @@ The repository holds:
89
- [`.github/workflows/quarto-render.yml`](.github/workflows/quarto-render.yml): Install, setup, and render a Quarto book using R and Python
910
- [`_quarto.yml`](_quarto.yml): Setup the properties of the book in a minimal fashion (for more options see [Quarto: Book Structure](https://quarto.org/docs/books/book-structure.html))
1011
- [`index.qmd`](index.qmd): Welcome page
11-
12-
Additional files:
13-
14-
- [`requirements.txt`](requirements.txt): List of Python Packages to install
1512
- [`DESCRIPTION`](DESCRIPTION): List of R Packages using the standard DESCRIPTION file to install with `pak`.
1613

1714
## Publishing with GitHub Actions
18-
19-
Included in the repository is a custom GitHub Action that will automatically render and deploy the book onto GitHub Pages.
20-
Before the first run of the GitHub Action, please make sure to use locally in terminal the following:
21-
22-
```sh
23-
quarto publish gh-pages
24-
```
25-
26-
This command [initializes the `gh-pages` branch and turns on GitHub Pages for the repository](https://quarto.org/docs/publishing/github-pages.html#source-branch).
27-
28-
If you do not run this command before the first GitHub Action is triggered, you will likely encounter the following error message in the build log:
29-
30-
```sh
31-
ERROR: No _publish.yml file available (_publish.yml specifying a destination required for non-interactive publish)
32-
```
33-
34-
To avoid this issue, please make sure to run the GitHub Action locally so that GitHub can render and publish your Quarto document after every push to the repository.

_quarto.yml

+17-5
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,37 @@ project:
33
output-dir: _book
44

55
book:
6-
title: "Title of Next Bestseller"
6+
title: "R Reference"
77
author: "JJB"
88
description: |
99
TBA
1010
#cover-image: images/cover.png
11-
site-url: https://tutorials.thecoatlessprofessor.com/quarto-book-template
12-
repo-url: https://github.com/coatless-tutorials/quarto-book-template
11+
site-url: https://textbooks.thecoatlessprofessor.com/r-reference
12+
repo-url: https://github.com/coatless-textbooks/r-reference
1313
repo-branch: main
1414
repo-actions: [edit]
1515
sharing: [twitter, facebook, linkedin]
1616
chapters:
1717
- index.qmd
18-
- part: my-first-book.qmd
18+
- part: "Graphics"
1919
chapters:
20-
- hello-world.qmd
20+
- base-r-graphics.qmd
21+
- part: "Configuration"
22+
chapters:
23+
- r-environment-variables.qmd
24+
- part: "Parallelization"
25+
- part: "Compiled Code"
2126
appendices:
2227
- appendix-notes.qmd
2328

2429
format:
2530
html:
2631
theme: cosmo
2732
code-link: true
33+
34+
# Register Adsense plugin to appear on all pages
35+
adsense:
36+
publisher-id: ca-pub-4979996562647159
37+
38+
filters:
39+
- adsense

base-r-graphics.qmd

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Base R Graphics
2+
3+
4+
## Customizing Plot Appearance
5+
6+
### Adjusting Axis Labels and Titles
7+
8+
```{r}
9+
# Example 1
10+
x <- 1:10
11+
y <- x^2
12+
plot(x, y, main = "Quadratic Function", xlab = "X", ylab = "Y")
13+
14+
# Example 2
15+
df <- data.frame(Time = 1:10, Value = cumsum(rnorm(10)))
16+
plot(df$Time, df$Value, main = "Cumulative Sum", xlab = "Time", ylab = "Cumulative Value")
17+
```
18+
19+
### Changing Line Types, Colors, and Symbols
20+
21+
```{r}
22+
# Example 1
23+
x <- 1:5
24+
y1 <- x
25+
y2 <- 2 * x
26+
y3 <- 3 * x
27+
28+
plot(x, y1, type="b", col="red", pch=16, lty=1, ylim=c(0, 15), main="Multiple Lines Example")
29+
points(x, y2, col="blue", pch=17, lty=2)
30+
lines(x, y3, col="green", lty=3)
31+
32+
# Example 2
33+
set.seed(123)
34+
x <- rnorm(50)
35+
y <- x + rnorm(50, mean=2)
36+
plot(x, y, col="purple", pch=19, main="Scatter Plot with Customized Symbols", xlab="X", ylab="Y")
37+
```
38+
39+
```{r}
40+
# Create data
41+
x <- 1:10
42+
y <- 1:10
43+
44+
# Line Types
45+
par(mar=c(4, 4, 2, 2))
46+
plot(x, y, type="n", main="All Line Types", xlab="X", ylab="Y", ylim=c(0, 6))
47+
for (i in 0:5) {
48+
lines(x, rep(i*.5, length(x)), lty=i, col="black", lwd=2)
49+
}
50+
51+
legend("topright", legend=0:5, title="Line Types", lty=0:5, col="black", lwd=2, ncol=3)
52+
```
53+
54+
```{r}
55+
# Colors
56+
par(mar=c(4, 4, 2, 2))
57+
plot(x, y, type="n", main="All Colors", xlab="X", ylab="Y", ylim=c(0, 9))
58+
for (i in 1:8) {
59+
lines(x, rep(i*.5, length(x)), col=i, lwd=2)
60+
}
61+
62+
legend("topright", legend=1:8, title="Colors", col=1:8, lwd=2, ncol=2)
63+
```
64+
65+
```{r}
66+
# symbols
67+
# todo
68+
```

hello-world.qmd

-3
This file was deleted.

index.qmd

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
11

2-
32
## Welcome {.unnumbered}
43

5-
Welcome splash page! Provide an overview of the book.
6-
7-
Sample evaluation of R and Python in a side-by-side manner:
8-
9-
::: {layout-ncol=2}
10-
#### R
11-
12-
```{r}
13-
my_list = list(1, 2, 3)
14-
typeof(my_list)
15-
```
16-
17-
#### Python
18-
19-
```{python}
20-
my_list = [1, 2, 3]
21-
type(my_list)
22-
```
23-
:::
4+
Hello there! You've stumbled across a reference guide that contains different useful R code and/or links. There isn't a lot of depth associated with each page if you are expecting a through walkthrough of the material.

r-environment-variables.qmd

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# R Environment Variables
2+
3+
Setting up and using environment variables in R is useful for handling configuration
4+
details and/or suppressing private information.
5+
6+
## Retrieve/access environment variables:
7+
8+
Values stored in the system environment can be retrieved using `Sys.getenv("VAR_NAME")`.
9+
10+
```{r}
11+
# Example: Accessing environment variable named API_KEY
12+
api_key <- Sys.getenv("API_KEY")
13+
api_key
14+
```
15+
16+
In the case where the value might not be found, make sure to specify an **unset** value that acts as a default.
17+
18+
```{r}
19+
# Example: Accessing environment variable named API_KEY
20+
api_key <- Sys.getenv("API_KEY", unset = NA)
21+
api_key
22+
```
23+
24+
Note, the `Sys.getenv()` function only returns a `character` value.
25+
26+
## Set environment variables in your R environment
27+
28+
Environment variables can be set in R by using `Sys.setenv()`.
29+
30+
```{r}
31+
Sys.setenv(API_KEY = "your_api_key")
32+
```
33+
34+
## Use an `.Renviron` file for configuration:
35+
36+
Frequently using environment variables? Instead of defining them for each script, aim to store
37+
environment variables in a `.Renviron` file in the project directory.
38+
39+
Variables are specified in the `.Renviron` file with the format `VAR_NAME=value`.
40+
41+
:::callout-note
42+
Avoid using spaces around the `=` sign.
43+
:::
44+
45+
```ini
46+
# Example .Renviron file
47+
API_KEY=your_api_key
48+
```
49+
50+
## Access `.Renviron` from R using `browseURL()` or `usethis` package
51+
52+
The `.Renviron` file may be accessed using either `browseURL("~/.Renviron")` or with `usethis::edit_r_environ()` for editing.
53+
54+
```{r}
55+
#| eval: false
56+
# Example: Load .Renviron file with browseURL()
57+
utils::browseURL("~/.Renviron")
58+
```
59+
60+
```{r}
61+
#| eval: false
62+
# Example: Load .Renviron file with the usethis package
63+
usethis::edit_r_environ()
64+
```
65+
66+
### TODO: mention `dotenv` for managing environment variables?

r-reference.code-workspace

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {}
8+
}

0 commit comments

Comments
 (0)