Usage of local variables Usage of local variables r r

Usage of local variables


Use local. Using your example:

local({      V1 = c(1,2,3);     V2 = c(1,2,3);     P = inner_product(V1, V2);     print(P);})# the variable V1, V2, P are undefined here!


You can create a new environment where your variable can be defined; this is how the local scope within a function is defined.

You can read more about this here

check the help for environment as well i.e. type in your R console ?environment