For loop not updating variable

The overarching reason is in the class of problems that Inigo Montoya with respect to Vizzini's frequent use of the word inconceivable to express surprise or to cast doubt on some future course of events' predicted outcome. In users trained in imperative/procedural languages it seems an immutable property of the universe that a variable springs into being immediately upon its assignment of a value.

In a procedural language (at least as it usually presents to the user) such as R that is only partially true. Because lazy evaluation and environment scoping.

What happens in Vegas stays in Vegas —The Hospitality Commission, or whatever they call it.

Let f(x) = y where x is the cash and credit brought to the table and y is whatever amount greater than x or, more likely y<<x. Think of the environment in which f operates as its local environment. But just as the punter stays in Vegas before going home, the states that x stay in a f until it returns some value of y to become part of the global environment.

Within f objects in the global environment can be changed, as done with

kCounts exists in the global environment, as does its successive subsets. This

creates a local version , within for of all_perm and in every iteration along kCount creates a new version. In R it is often difficult to perceive the intent when presented procedurally.

Can you show the structure of the object you are trying to create with a reprex. See the F AQ. Then we can work on how to express this in a vectorized fashion.

On the other hand, if you are wed to C/C++, there's a package to import functions into namespace.

1 Like