I'm currently reading Hands-On Programming With R and the author first suggests this code to deal cards from the top of a deck:
deal <- function(deck) {
deck[1,]}
but that code has an obvious problem: you'll always get the same card, since the function does not remove the card from the deck after it has been dealt.
As a solution, he suggests this code:
deal <- function(){
card <- deck[1,]
assign("deck", deck[-1,], envir = globalenv())
card
I feel like I don't properly understand what's going on with the envir = globalenv() part. I do know that it has something to do with removing the card that has been dealt from the deck, but can someone please elucidate what is happening there exactly?