[R-SIG-Finance] a concern about blotter (and RStudio)

Brian G. Peterson brian at braverock.com
Mon Jun 4 12:39:24 CEST 2012


On 06/03/2012 08:13 PM, dae wrote:
>
> braverock wrote
>>
>> You can recreate an (empty) .blotter environment with this code:
>>
>> .blotter<- new.env()
>>
>>
>
> How does new.env()  relate to the namespace?
>
> library(blotter) won't create .blotter
> unless the old namespace is unloaded when
> it's detached.
>      detach("package:blotter", unload=TRUE)
> [and if  .blotter does not exist]

the .blotter environment is created initially for the user (if it does 
not already exist) in the .onLoad function of the package.

If you are using project directories (as supported by RStudio and 
recommended in many texts on best practices for programming in R), you 
can then leave the .blotter environment for your project in a known 
state and come back to it to work on later.

One example is incrementally adding production or simulated transactions 
as more data becomes available in subsequent days.

I suspect that if detach is called without unload=TRUE, that .onLoad may 
not get called when the package is reloaded.  This would suggest a 
possible unintended behavior in RStudio.

Another option is that the .onLoad function in blotter isn't 'smart' 
enough to figure out that it needs to recreate a new.env() .blotter for 
the user in the user's .GlobalEnv

To directly answer your question, new.env() has nothing to do with the 
blotter package namespace.  As I said before, it is a workaround that 
recreates it.  if a .blotter environment already existed, calling

.blotter<- new.env()

would unceremoniously clobber it.

Regards,

   - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list