Hi,I am trying to run the faber.R demo within a function Here is the urlhttps://r-forge.r-project.org/scm/viewvc.php/pkg/quantstrat/demo/faber.R?view=markup&root=blotter Within a function, when the 'faber.R code reaches initPortf() the following error is thrown. Error in exists(paste("portfolio", name, sep = "."), envir = .blotter, : object '.blotter' not found # what I have done to fix is insert the following code # and tested running # within a function # within a lexical function # within R studio ( within a lexical function ) # just after# require(quantstrat) call# required ( If I am running in a function )if(!is.null(sys.call(sys.parent()))) { if (!exists('.blotter' , envir=.GlobalEnv )) { .GlobalEnv$.blotter <- new.env() } if (!exists('.strategy', envir=.GlobalEnv )) { .GlobalEnv$.strategy <- new.env() } } # just after# getSymbols( . . . ) call# optional: ( If I am running in a function )# does not affect the program ( but for consistency if nothing else )# note: .getSymbols is not an environmentif(!is.null(sys.call(sys.parent()))) { .GlobalEnv$.getSymbols <- .getSymbols} # just after # assign(symbol,x) call# required ( If I am running in a function )if(!is.null(sys.call(sys.parent()))) { assign(symbol,x, envir = .GlobalEnv)} # RStudio # surrounding any dev() OR chart.#() calls# dev() # Only one RStudio graphics device is permitted# chart # RStudio margins errorif (!any(search() %in% "tools:rstudio")) { # ...} # Does any other easier way exist, so I do not have to modify# so much code? Thanks,Andre [email protected] [[alternative HTML version deleted]]
_______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
