Lexical Scoping - assignment 2 of R programming Coursera