Explain R environments like I’m five
“Can you explain me what are environments in R?”The beginning of a series of blogpost about R concepts, explained to mydaughter. Side note: no, my daughter is not five, and she’s not named Alice. Andshe doesn’t speak english either ¯\(ツ)/¯.“Daddy, I’ve seen you reading this book with a weird chapter named‘Environments in R’. What does it mean?”“Alice darling, just sit down for a minute.Let’s say the world is a big computer, and everyone living in it is apiece of information we call ‘data’. Right now, we are at home, and homeis a small piece from the whole world. In R, these smaller places arecalled environments, and they are used just as our home: they cancontain data, and we can refer to these data with names which arespecific to the environment.For example, when we are at home, there are five pieces of data: you,me, mommy, and the two cats. At home, I can say ‘Darling’, and as we arein this small subset of the whole world where ‘darling’ refers to you,I’m pretty sure I will find you. But if I go in another home, that isto say in another environment with other data, another dad is callinghis daughter ‘Darling’. In this small other environment, different fromours, ‘Darling’ does not refer to the same piece of data. And the samegoes for “Mommy” and “Daddy”: in another home, they refer to otherpersons.If I go out in the wild world and try to use the word ‘Mommy’, thiswon’t specifically refer to your mum, as there are not one single‘Mommy’ in this world, and because this word refers to someonespecific to the home we are using it in. In the wild world, if I want torefer to your mum, I’ll need to specify from which home the ‘Mommy’ I’mlooking for is coming from.”“So why don’t we use the full name every time then? It seems simpler.”“Environments allow us to use the same word to refer to different data,depending on where we are using the word. It also allows to giveinformation about a piece of data: it’s quite normal to think that afather uses ‘Darling’ to refer to someone he loves very very much. Evenif, strictly speaking, nothing prevents the contrary from happening.Also, it wouldn’t be fair to only allow only one ‘Darling’ in the wholeworld. Thanks to environment, there won’t be any problem if every fatherin the world use this word, as it refers, in each home, to a specificlittle girl.”“Ok, thanks dadddy!”“You’re welcome, Darling”The R code behindAbout environments# Creating two houseshome