Problem:
How to define local variables within a scope in a r-code.
Example:
In C++ the following example defines a
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
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!