Subject: Re: [R] keep track of variables created in each chapter of a knitr
> book
>
> You could initialize one list per chapter,
>
> > x1 <- list( "Chapter One" )
>
> and then crate your variables as list members
>
> > x1$A <- c( 1
You could initialize one list per chapter,
> x1 <- list( "Chapter One" )
and then crate your variables as list members
> x1$A <- c( 1, 2, 3 )
> x1$B <- "bla"
> x1$tv.data <- data.frame( m = sample( LETTERS, 5 ),
n = round( runif( 5 ), 2 ) )
> x1
[[1]]
[1] "Chapter O
I'm not sure what exactly you want to remove in the cleanup step, but
to list the objects assigned in a particular chapter can't you just
put
prev.vars <- ls()
at the beginning of the chapter and
vars.this.chapter <- setdiff(ls(), prev.vars)
at the end?
Best,
Ista
On Fri, Jan 24, 2014 at 9:14
In a book project using knitr, I'm creating a large number of variable
and objects in chunks within
chapters. I'd like to find a way of keeping track of all of those for
each chapter, and clean up
at the end of each chapter, without having to manually list their names
as shown below.
The book
4 matches
Mail list logo