|
- ---
- title: "Test"
- author: "Pjotr"
- date: "24/02/2020"
- output: html_document
- ---
-
- ```{r setup, include=FALSE}
- knitr::opts_chunk$set(echo = TRUE)
- ```
-
- ## R Markdown
-
- This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
-
- When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
-
- ```{r cars}
- summary(cars)
- ```
-
- ## Including Plots
-
- You can also embed plots, for example:
-
- ```{r pressure, echo=FALSE}
- plot(pressure)
- ```
-
- Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
-
- ## Environments
-
-
- R environments are used to bind names against values. In
- this case the subjectid is the name.
-
- ```{r}
- id <- new.env()
- id$16K0021 = 'first'
- ```
-
- oops, can't start with a number
-
- ```{r}
- id$m16K0021 = 'first'
- ls(id, all.names = TRUE)
- ```
-
- Note that data frames use environment too with the $ notation.
-
- To add material to an environment we create a new environment (a hash of hash). So
-
- ```{r}
- mydata <- new.env()
- mydata$days = 21
- mydata$name = "Pjotr Prins"
- id$m16K0021 = mydata
- ls(id$m16K0021, all.names = TRUE)
- id$m16K0021$name
- ```
-
- That works well. Step is to be able to parametrize
-
- ```{r}
- id[["m16K0021"]]$days
- ```
-
- So you can see the dollar notation is just syntactic sugar.
-
- ```{r}
- id[["m16Ktest"]] = new.env()
- test = id[["m16Ktest"]]
- test$name = "Jan Wolkers"
- test$days = 22
- ls(id, all.names = TRUE)
- ls(test, all.names=TRUE)
- test$name
- ```
-
-
- See also http://adv-r.had.co.nz/Environments.html
|