-
Notifications
You must be signed in to change notification settings - Fork 46
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
Drop generator attributes #173
Conversation
They don't appear to be used for anything, and interfere with code navigation.
The purpose of the library(logger)
log_appender()
#> appender_console
log_appender(appender_file(file = "/tmp/foobar"))
log_appender()
#> appender_file(file = "/tmp/foobar") If we don't keep track of this, then the user will see something like: function (lines)
{
if (is.finite(max_lines) | is.finite(max_bytes)) {
fail_on_missing_package("R.utils")
n_lines <- tryCatch(suppressWarnings(R.utils::countLines(file)),
error = function(e) 0)
n_bytes <- ifelse(file.exists(file), file.info(file)$size,
0)
if (n_lines >= max_lines || n_bytes >= max_bytes) {
log_trace("lines: %s, max_lines: %s, bytes: %s, max_bytes: %s",
n_lines, max_lines, n_bytes, max_bytes, namespace = ".logger")
log_trace("lines >= max_lines || bytes >= max_bytes: %s",
n_lines >= max_lines || n_bytes >= max_bytes,
namespace = ".logger")
for (i in max_files:1) {
if (i == 1) {
log_trace("killing the main file: %s", file,
namespace = ".logger")
unlink(file)
}
else {
new <- paste(file, i - 1, sep = ".")
if (i == 2) {
old <- file
}
else {
old <- paste(file, i - 2, sep = ".")
}
if (file.exists(old)) {
log_trace("renaming %s to %s", old, new,
namespace = ".logger")
file.rename(old, new)
}
if (i > max_files) {
log_trace("killing the file with too many rotations: %s",
new, namespace = ".logger")
unlink(new)
}
}
}
}
}
log_trace("logging %s to %s", shQuote(lines), file, namespace = ".logger")
cat(lines, sep = "\n", file = file, append = append)
}
<bytecode: 0x5f8022b5b078>
<environment: 0x5f8022b602a8> But I'm open to solving this more elegantly. |
Oh I missed where it was used. If you want to keep this behaviour, I think it would be a little easier to capture it when you use |
Usually, the generator is defined via |
A simpler approach might just be to adopt a syntax like this: generator <- function(x) attr(x, "generator")
`generator<-` <- function(x, value) {
attr(x, "generator") <- value
x
}
appender_void <- function(lines) {}
generator(appender_void) <- quote(appender_void()) |
I've spent some time trying to capture the The above |
I'll take a pass through with the generator approach so you can see what you think. It might possibly also need a |
They don't appear to be used for anything, and interfere with code navigation.