Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.xts - interactive inspection #79

Open
timelyportfolio opened this issue Apr 21, 2015 · 0 comments
Open

plot.xts - interactive inspection #79

timelyportfolio opened this issue Apr 21, 2015 · 0 comments
Labels

Comments

@timelyportfolio
Copy link

This is not really an issue, but I thought this might be the best place to demonstrate how someone might inspect a plot object. I remember struggling a lot with this when I first started working with quantmod primarily due to my ignorance around R environments. This is far from perfect, but might be helpful for someone who wants to understand the structure better.

library(rlist) # for list.parse

list_attributes <- function( la ){
  ln <- list()

  list_recursive <- function (lb){
    class_name = class(lb)
    lb <- if(is.environment(lb) ) as.list(lb) else lb
    lb <- if(is.expression(lb)) {
      expr_str <- list("expression" = as.character(lb))
      attributes(expr_str) <- attributes(lb)
      expr_str
    } else {
      lb
    }

    if( is.list(lb) ) {
      list(
        attrib = lapply(
          attributes(lb)
          ,function(lattrib){
            if(is.environment(lattrib)){
              capture.output(str(lattrib))
            } else{
              lattrib
            }
          }
        )
        , class = class_name
        , children = lapply( lb, list_recursive )
      )
    } else if( inherits(lb, c("zoo", "xts", "data.frame") ) ) {
      ldf <- list.parse( data.frame(lb) )
      list( attrib = attributes(lb), class = class_name, data = ldf)
    } else {
      list( class = class_name, value = lb)
    }
  }

  ln[[deparse(substitute(la))]] <- list_recursive(la)
  return(ln)
}

library(xts)

data(sample_matrix)
sample_xts <- as.xts(sample_matrix)
p <- plot( sample_xts[,"Close"])

# devtools::install_github( "timelyportfolio/listviewer" )
library( listviewer )
jsonedit( list_attributes(p) )


xts:::current.xts_chob()
structure(xts:::current.xts_chob(),class=c("replot_xts","environment"))

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants