).
There are two ways to get these project files into you PC/Laptop:
- (Recommended) You can download the **“.zip”** file by click “Download”
button after you click the URL show before.
- Use tools like `gitbash` to **clone** or **fork** the whole project.
Finally, the project directory structure will be shows as bellow:
D:/github/course-emiii-accompany
├── course-emiii-accompany.Rproj
├── index.qmd
├── IV-wage-card
│ ├── card1995.dta
│ └── code-card-hansen.R
├── IV-wage-mroz
│ ├── code-mroz.R
│ ├── mroz-var-label.txt
│ ├── workingpaper.qmd
│ └── workingpaper_files
├── menu
│ ├── iv-wage-card.qmd
│ ├── iv-wage-mroz.qmd
│ ├── project-prepare.qmd
│ └── sem-wage-mroz.qmd
├── pic
│ └── logo
├── R
│ ├── helper-tidy-systemfit.R
│ └── load-pkg-basic.R
├── README.qmd
├── README.rmarkdown
├── renv
│ ├── activate.R
│ ├── library
│ └── staging
├── renv.lock
├── scss
│ ├── styles.css
│ └── _variables.scss
├── sem-wage-mroz
│ └── code-sem-mroz.R
├── _freeze
│ ├── index
│ ├── IV-wage-mroz
│ ├── menu
│ └── site_libs
├── _quarto.yml
└── _site
├── index.html
├── IV-wage-mroz
├── menu
├── pic
├── README.qmd
├── scss
├── search.json
└── site_libs
## Step 3/3:Install R packages
R is a function-based object-oriented programming language. When
executing R code commands, various R packages are often used to achieve
specific programming goals.
After you have downloaded the project file to your local computer (Step
2/3), you can open the project with Rstudio (Step 1/3), then open
‘R/load-pkg-basic.R’(see below) to see the relevant R packages needed
for this project and install them.
**R/load-pkg-basic.R**
``` r
# load necessary R packages
# system
library(rmarkdown)
library(renv) # package management
library(yaml) # quarto project
library(fs) # file system management
library(here) # relative path
# basic pkgs
library(tidyverse) # most useful
library(magrittr) # pipe %>%
library(knitr) # R render engine
# read file
library(openxlsx) # for excel file
library(foreign) # for stata file
# viz
library(ggplot2) # graph
library(DT) # DT table
library(scales) # tidy numbers
library(webshot2) # snapshot
library(htmlwidgets) # interactivity
#library(fontawesome)
# github repo
#renv::install("KWB-R/kwb.utils")
#renv::install("huhuaping/xmerit") # developed by `Huhuaping`
#library(xmerit) # export Latex equation
```
> [!TIP]
>
> To put it simply, R packages come from a few main sources:
>
> - The base package by the R core team
>
> - R packages developed by the R community (widely published on github
> and other hosting platforms)
>
> - Other source of R packages
How to install these R packages?
Solution 1 (**Not recommend**): use `install.packages("foo")` to install
all packages one by one.
Solution 2 (**Strongly recommend**) : use `renv` package management tool
chain!
- Open the course project with `Rstudio` (double click
`course-emiii-accompany.Rproj`). Then you can write and run R command
in panel `Console` below the software window.
- First, write and run R command `install.packages("renv")`
- Then, write and run R command `library(renv)`
- Finally, write and run R command `renv::active()` and
`renv::restore()`