# Demonstrate R objects of various types. # For the class Mathematics in Finance # http://www.math.nyu.edu/faculty/goodman/teaching/MathFin/index.html # Author: Jonathan Goodman rm( list = ls()) Age = 29 # and not a day more Boys = c("Jack", "Daniels") candles = 1:Age debt = numeric(Age) # Allocate the array, calculate later extras = c(1.2, 1, "word") f = function(x){ r = sqrt( x^2 + y^2 ) cat("\n Objects inside f\n\n") ObjectNameList = ls() for ( ObjectName in ObjectNameList){ object = get0( ObjectName) cat(ObjectName, " has type ", typeof(object), "\n") } return(r) } cat("\n Objects before deleting\n\n") ObjectNameList = ls() for ( ObjectName in ObjectNameList){ object = get0( ObjectName) cat(ObjectName, " has type ", typeof(object), "\n") } rm(Age) rm(debt) # I wish cat("\n Objects after deleting\n\n") ObjectNameList = ls() for ( ObjectName in ObjectNameList){ object = get0( ObjectName) cat(ObjectName, " has type ", typeof(object), "\n") } y = 4 cat("This number should be five: ", f(3), "\n")