Discussion:
[Roxygen-devel] [roxygen2] error sourcing the R files (probably environment issue)
Renaud Gaujoux
2011-09-21 13:41:51 UTC
Permalink
Hi,

in one of the R files I have something like this, that defines a
temporary function in order to define a static variable:

f <- function(){
.a <- 0
function(x=1){
.a <<- .a + x
.a
}
}
f2 <- f()
rm(f)

When running roxygenise on this I get the error:
Error in eval(expr, envir, enclos) : object 'f' not found

No error with R CMD check.
If I use the -- very nice -- function devtools::load_all, it works
perfectly fine as well.

In this simple case I know I could do f <- f() instead and remove the
problematic call to rm (and it works fine).
But my actual use case is to define a S4 method like this:

setMethod('A', 'ANY', f())
rm(f)

Here I really need to remove not to have it remaining in my namespace.

Does roxygen2 source the R files differently?
Maybe there is an alternative way to define static variables for my use
case, that would not break roxygenise?

Thank you

Renaud



###

UNIVERSITY OF CAPE TOWN

This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 9111. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity.

###
Hadley Wickham
2011-09-21 19:38:04 UTC
Permalink
in one of the R files I have something like this, that defines a temporary
f <- function(){
? ?.a <- 0
? ?function(x=1){
? ? ? ?.a <<- .a + x
? ? ? ?.a
? ?}
}
f2 <- f()
rm(f)
Error in eval(expr, envir, enclos) : object 'f' not found
What does traceback give you? Could you provide a small reproducible example?

Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
Renaud Gaujoux
2011-09-21 20:44:01 UTC
Permalink
The sample code in my post should be enough to reproduce the issue.
I have wrapped it into a package (attached to this post).

Renaud
Post by Hadley Wickham
in one of the R files I have something like this, that defines a temporary
f<- function(){
.a<- 0
function(x=1){
.a<<- .a + x
.a
}
}
f2<- f()
rm(f)
Error in eval(expr, envir, enclos) : object 'f' not found
What does traceback give you? Could you provide a small reproducible example?
Hadley
###

UNIVERSITY OF CAPE TOWN

This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 9111. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity.

###


-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_1.0.tar.gz
Type: application/x-gzip
Size: 479 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/roxygen-devel/attachments/20110921/161c9a7e/attachment.bin>
Hadley Wickham
2011-09-21 21:48:47 UTC
Permalink
Could you please file an issue at https://github.com/klutometis/roxygen/issues?
Thanks!
Hadley
Post by Renaud Gaujoux
The sample code in my post should be enough to reproduce the issue.
I have wrapped it into a package (attached to this post).
Renaud
in one of the R files I have something like this, that defines a temporary
f<- function(){
? ?.a<- 0
? ?function(x=1){
? ? ? ?.a<<- .a + x
? ? ? ?.a
? ?}
}
f2<- f()
rm(f)
Error in eval(expr, envir, enclos) : object 'f' not found
What does traceback give you? ?Could you provide a small reproducible
example?
Hadley
###
UNIVERSITY OF CAPE TOWN
This e-mail is subject to the UCT ICT policies and e-mail disclaimer
published on our website at
http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27
21 650 9111. This e-mail is intended only for the person(s) to whom it is
addressed. If the e-mail has reached you in error, please notify the author.
If you are not the intended recipient of the e-mail you may not use,
disclose, copy, redirect or print the content. If this e-mail is not related
to the business of UCT it is sent by the sender in the sender's individual
capacity.
###
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
Renaud Gaujoux
2011-09-22 10:21:25 UTC
Permalink
Done:
https://github.com/klutometis/roxygen/issues/42

Thank you
Post by Hadley Wickham
Could you please file an issue at https://github.com/klutometis/roxygen/issues?
Thanks!
Hadley
Post by Renaud Gaujoux
The sample code in my post should be enough to reproduce the issue.
I have wrapped it into a package (attached to this post).
Renaud
Post by Hadley Wickham
in one of the R files I have something like this, that defines a temporary
f<- function(){
.a<- 0
function(x=1){
.a<<- .a + x
.a
}
}
f2<- f()
rm(f)
Error in eval(expr, envir, enclos) : object 'f' not found
What does traceback give you? Could you provide a small reproducible example?
Hadley
###
UNIVERSITY OF CAPE TOWN
This e-mail is subject to the UCT ICT policies and e-mail disclaimer
published on our website at
http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27
21 650 9111. This e-mail is intended only for the person(s) to whom it is
addressed. If the e-mail has reached you in error, please notify the author.
If you are not the intended recipient of the e-mail you may not use,
disclose, copy, redirect or print the content. If this e-mail is not related
to the business of UCT it is sent by the sender in the sender's individual
capacity.
###
###

UNIVERSITY OF CAPE TOWN

This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 9111. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity.

###

Renaud Gaujoux
2011-09-21 20:46:15 UTC
Permalink
traceback()
12: eval(expr, envir, enclos)
11: eval(assignee, env)
10: parser(call, env)
9: FUN(X[[1L]], ...)
8: lapply(src_refs, parse.srcref, env = env)
7: force(code)
6: parse_cache$compute(c(env_hash, readLines(file, warn = FALSE)),
{
src_refs <- attributes(parse(srcfile$filename, srcfile =
srcfile))$srcref
pre_refs <- prerefs(srcfile, src_refs)
if (length(src_refs) == 0)
return(list())
src_parsed <- lapply(src_refs, parse.srcref, env = env)
pre_parsed <- lapply(pre_refs, parse.preref)
stopifnot(length(src_parsed) == length(pre_parsed))
mapply(c, src_parsed, pre_parsed, SIMPLIFY = FALSE)
})
5: FUN("/home/renaud/Documents/tmp/test/R/fun.R"[[1L]],
...)
4: lapply(paths, parse.file, env = env, env_hash = env_hash)
3: unlist(lapply(paths, parse.file, env = env, env_hash = env_hash),
recursive = FALSE)
2: parse.files(r_files)
1: roxygenise(".")
--
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa
in one of the R files I have something like this, that defines a temporary
f<- function(){
.a<- 0
function(x=1){
.a<<- .a + x
.a
}
}
f2<- f()
rm(f)
Error in eval(expr, envir, enclos) : object 'f' not found
What does traceback give you? Could you provide a small reproducible example?
Hadley
###

UNIVERSITY OF CAPE TOWN

This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 9111. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity.

###
Loading...