Every time I try to roxygenize a package I get this error:
Error: is.call(call) is not TRUE
The results of a traceback():
11: stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"),
ch), call. = FALSE, domain = NA)
10: stopifnot(is.call(call))
9: standardise_call(call, env)
8: object_from_call(call, env, preref)
7: (function (call, ref, comment_ref)
{
preref <- parse.preref(as.character(comment_ref))
if (is.null(preref))
return()
preref$object <- object_from_call(call, env, preref)
preref$srcref <- list(filename = file, lloc = as.vector(ref))
add_defaults(preref)
})(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]])
6: mapply(FUN = f, ..., SIMPLIFY = FALSE)
5: Map(extract, parsed, refs, comment_refs)
4: FUN(c("/home/path/to/package/file1.r",
"/home/path/to/package/file2.r",
.... # list of files truncated
"/home/path/to/package/doc.file.r")[[25L]],
...)
3: lapply(r_files(base_path), parse_file, env = env)
2: parse_package(base_path, load_code)
1: roxygenize("~/Current/r/path/to/package/")
Has anyone experienced this problem before? I'm not even sure how to debug it further.
This error occurs if, instead of the typical NULL value that one puts at the end of the documentation for the package, one uses NA. Simply updating to NULL will remove the error.
Related
I seem to have a weird combination of NSE, rmarkdown and callr, similar in flavor to Is it possible to disable `callr` for RMarkdown?.
When I set a value to a variable to use it in something similar to a filter call implemented using NSE via nested evals and list calls, it fails horribly, but only in callr.
---
title: "Test CC2 Failure Reproducibly"
author: "Robert M Flight"
output: rmarkdown::md_document
editor_options:
chunk_output_type: console
---
```{r run_enrichments}
set.seed(1234)
create_go_annotation = function(db, ontology = NULL){
all_genes = keys(db)
go_all_gene = AnnotationDbi::select(db, keys = all_genes, columns = c("GOALL", "ONTOLOGYALL"))
if (!is.null(ontology)) {
go_all_gene = go_all_gene[go_all_gene$ONTOLOGYALL == ontology, ]
ontology_type = paste0("GO.", ontology)
} else {
ontology_type = "GO.all"
}
go_2_gene = split(go_all_gene$ENTREZID, go_all_gene$GOALL)
go_2_gene = lapply(go_2_gene, unique)
go_desc = AnnotationDbi::select(GO.db::GO.db, keys = names(go_2_gene), columns = "TERM", keytype = "GOID")$TERM
names(go_desc) = names(go_2_gene)
go_annotation = categoryCompare2::annotation(annotation_features = go_2_gene,
description = go_desc,
annotation_type = ontology_type,
feature_type = "ENTREZID")
go_annotation
}
library(org.Hs.eg.db)
library(GO.db)
library(categoryCompare2)
library(methods)
go_mf = create_go_annotation(org.Hs.eg.db, "MF")
all_features = unique(unlist(go_mf#annotation_features))
sig_features = sample(all_features, 500)
enrich = hypergeometric_feature_enrichment(
new("hypergeom_features", significant = sig_features,
universe = all_features,
annotation = go_mf),
p_adjust = "BH"
)
comb_enrich = combine_enrichments(sig1 = enrich)
sig_cutoff = 0.1
filter_enrich = get_significant_annotations(comb_enrich, padjust <= sig_cutoff)
```
Run it via callr:
r(function() rmarkdown::render(here::here("categoryCompare2_failure.Rmd"), output_file = "cc2_fails_1.md"), show = TRUE)
# Quitting from lines 13-57 (categoryCompare2_failure.Rmd)
#
# Error in FUN(X[[i]], ...) : object 'sig_cutoff' not found
# Error: callr subprocess failed: object 'sig_cutoff' not found
# > .Last.error.trace
# Stack trace:
# Process 221313:
# 1. callr:::r(function() rmarkdown::render(here::he ...
# 2. callr:::get_result(output = out, options)
# 3. throw(newerr, parent = remerr[[2]])
# x callr subprocess failed: object 'sig_cutoff' not found
# Process 221619:
# 15. (function () ...
# 16. rmarkdown::render(here::here("categoryCompare2_failure.Rmd"))
# 17. knitr::knit(knit_input, knit_output, envir = envir, quiet ...
# 18. knitr:::process_file(text, output)
# 19. base:::withCallingHandlers(if (tangle) process_tangle(gro ...
# 20. knitr:::process_group(group)
# 21. knitr:::process_group.block(group)
# 22. knitr:::call_block(x)
# 23. knitr:::block_exec(params)
# 24. knitr:::eng_r(options)
# 25. knitr:::in_dir(input_dir(), evaluate(code, envir = env, n ...
# 26. knitr:::evaluate(code, envir = env, new_device = FALSE, k ...
# 27. evaluate::evaluate(...)
# 28. evaluate:::evaluate_call(expr, parsed$src[[i]], envir = e ...
# 29. evaluate:::timing_fn(handle(ev <- withCallingHandlers(wit ...
# 30. base:::handle(ev <- withCallingHandlers(withVisible(eval( ...
# 31. base:::withCallingHandlers(withVisible(eval(expr, envir, ...
# 32. base:::withVisible(eval(expr, envir, enclos))
# 33. base:::eval(expr, envir, enclos)
# 34. base:::eval(expr, envir, enclos)
# 35. categoryCompare2:::get_significant_annotations(comb_enric ...
# 36. categoryCompare2:::get_significant_annotations(comb_enric ...
# 37. categoryCompare2:::.get_significant_combined_enrichment(i ...
# 38. base:::lapply(in_results#enriched, function(x) { ...
# 39. categoryCompare2:::FUN(X[[i]], ...)
# 40. categoryCompare2:::get_significant_annotations(x#statisti ...
# 41. categoryCompare2:::get_significant_annotations(x#statisti ...
# 42. categoryCompare2:::.get_significant_stat_results(in_resul ...
# 43. categoryCompare2:::multi_query_list(in_results#statistic_ ...
# 44. base:::lapply(queries, eval, list_to_query)
# 45. base:::FUN(X[[i]], ...)
# 46. base:::FUN(X[[i]], ...)
# 47. base:::.handleSimpleError(function (e) ...
# 48. h(simpleError(msg, call))
# x object 'sig_cutoff' not found
You can see that it complains that sig_cutoff is not found, but it exists in the environment, but does not seem to get passed down.
If I instead run it directly, it works:
rmarkdown::render(here::here("categoryCompare2_failure.Rmd"), output_file = "cc2_works.md")
I've put all the code in a github repo.
Interestingly, it's definitely a callr issue, because targets has the same issue.
callr v 1.0.7, rmarkdown v 2.11, R 4.1.0
Other package versions are in the renv.lock file.
Im trying to translate a lot of text from Italian to English using translateR in R. My file also contains other languages and I have successfully used translateR to translate these. The Italian represents the biggest amount though with over 4000 rows of short text segments to translate. Any idea what the problem is, or if there is a problematic data entry how to find it? I split the dataframe into half and the second half of the df appeared to run okay for a longer time than the original df but then the error message appeared again.
The error message is
Error in file(con, "r") : cannot open the connection
which doesnt tell me much. A traceback() gave the following:
16: file(con, "r")
15: readLines(content)
14: paste(readLines(content), collapse = "\n")
13: withCallingHandlers(expr, warning = function(w)
invokeRestart("muffleWarning"))
12: suppressWarnings(paste(readLines(content), collapse = "\n"))
11: structure(x, class = unique(c("AsIs", oldClass(x))))
10: I(suppressWarnings(paste(readLines(content), collapse = "\n")))
9: fromJSON(getURL(api.url))
8: fromJSON(getURL(api.url))
7: googleTranslate(x, google.api.key, source.lang, target.lang)
6: FUN(X[[i]], ...)
5: lapply(X, FUN, ...)
4: mclapply(to.translate, function(x) googleTranslate(x, google.api.key,
source.lang, target.lang))
3: unlist(mclapply(to.translate, function(x) googleTranslate(x,
google.api.key, source.lang, target.lang)))
2: unname(unlist(mclapply(to.translate, function(x) googleTranslate(x,
google.api.key, source.lang, target.lang))))
1: translate(content.vec = magg.it.2$text, google.api.key = "foo",
source.lang = "it", target.lang = "en")
Lately when I run my code that uses coxph in the survival package
coxph(frml,data = data), I am now getting warning messages of the following type
1: In model.matrix.default(Terms, mf, contrasts = contrast.arg) :
partial argument match of 'contrasts' to 'contrasts.arg'
2: In seq.default(along = temp) :
partial argument match of 'along' to 'along.with'"
I'm not exactly sure why all of a sudden these partial argument match warnings started popping up, but I don't think they effect me.
However, when I get the following warning message, I want coxph(frml,data = data) = NA
3: In fitter(X, Y, strats, offset, init, control, weights = weights, :
Loglik converged before variable 2 ; beta may be infinite.
6: In coxph(frml, data = data) :
X matrix deemed to be singular; variable 1 3 4
I used tryCatch when I wasn't getting the partial argument match warning using this code where if the nested tryCatch got either a warning or error message it would return NA
coxphfit = tryCatch(tryCatch(coxph(frml,data = data), error=function(w) return(NA)), warning=function(w) return(NA))
However, now that I am getting the partial argument match warnings, I need to only return an NA if there is an error or if I get the above warning messages 3 and 4 . Any idea about how to capture these particular warning messages and return an NA in those instances?
It's actually interesting question, if you are looking for quick and dirty way of capturing warnings you could simply do:
withCallingHandlers({
warning("hello")
1 + 2
}, warning = function(w) {
w ->> w
}) -> res
In this example the object w created in parent environment would be:
>> w
<simpleWarning in withCallingHandlers({ warning("hello") 1 + 2}, warning = function(w) { w <<- w}): hello>
You could then interrogate it:
grepl(x = w$message, pattern = "hello")
# [1] TRUE
as
>> w$message
# [1] "hello"
Object res would contain your desired results:
>> res
[1] 3
It's not the super tidy way but I reckon you could always reference object w and check if the warning message has the phrase you are interested in.
I'm trying to add a JUnit reporter to testthat. While I can do it inside the package (https://github.com/hadley/testthat/pull/481) I cannot make it pass the same set of tests when in a separate package (https://github.com/lbartnik/testthatJUnit).
My main problem is that tests designed for reporters and present in testthat do not pass if I pull JUnit reporter code to a separate package. I'm guessing that there is something in those tests that "sets the scene" for testing reporters but I'm unable to identify this "something".
Any help much appreciated.
Details follow.
> library(devtools)
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter:
DONE ==========================================================================
> test("testthat")
Loading testthat
unloadNamespace("testthat") not successful, probably because another loaded package depends on it.Forcing unload. If you encounter problems, please restart R.
Testing testthat
Bare expectations:
Colours: ..
compare.character: .................
compare.numeric: .....................
compare.time: .......
# ... lines cut ...
DONE ===========================================================================
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter: .............
If I modify the test to see why the first test("testthatJUnit") is silent I see this:
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter: Bare: .1
Failed -------------------------------------------------------------------------
1. Error: Junit reporter regression (#test-reporter-junit.R#13) ----------------
attempt to apply non-function
1: test_dir("test_dir") at /mnt/storage-a/lukaszb/src/third-party/testthatJUnit/tests/testthat/test-reporter-junit.R:13
2: test_files(paths, reporter = reporter, env = env, ...)
3: with_reporter(reporter = current_reporter, results <- lapply(paths, test_file, env = env,
reporter = current_reporter, start_end_reporter = FALSE, load_helpers = FALSE))
4: force(code)
5: lapply(paths, test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE,
load_helpers = FALSE)
6: FUN(X[[i]], ...)
7: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter, {
lister$start_file(basename(path))
source_file(path, new.env(parent = env), chdir = TRUE)
end_context()
})
8: force(code)
9: source_file(path, new.env(parent = env), chdir = TRUE)
10: eval(exprs, env)
11: eval(expr, envir, enclos)
12: expect_that(1, equals(1)) at test_dir/test-bare-expectations.R:3
13: condition(object)
14: expect_equal(x, expected, ..., expected.label = label)
15: expect(comp$equal, sprintf("%s not equal to %s.\n%s", lab_act, lab_exp, comp$message),
info = info)
16: withRestarts(if (expectation_broken(exp)) {
stop(exp)
} else {
signalCondition(exp)
}, continue_test = function(e) NULL)
17: withOneRestart(expr, restarts[[1L]])
18: doWithOneRestart(return(expr), restart)
19: signalCondition(exp)
20: (function (e)
{
register_expectation(e, frame + 11, sys.nframe() - 6)
invokeRestart("continue_test")
})(structure(list(message = "1 not equal to 1.\nEqual\n", srcref = NULL), .Names = c("message",
"srcref"), class = c("expectation_success", "expectation", "condition")))
21: register_expectation(e, frame + 11, sys.nframe() - 6)
22: get_reporter()$add_result(context = get_reporter()$.context, test = test, result = e)
23: o_apply(self$reporters, "add_result", context = context, test = test, result = result)
24: lapply(objects, function(x) x[[method]](...))
25: FUN(X[[i]], ...)
26: x[[method]](...)
But if I run test("testthat") and again test("testthatJUnit") everything comes back to normal:
> test("testthatJUnit")
Loading testthatJUnit
Testing testthatJUnit
JUnitReporter: Bare: ..
Basic: .......
empty: 1
error: 2.3456.
failures: 7.8..
helper: .
skip: S
My guess is that there is something in testthat's tests that sets up the scene for testing reporters but so far I haven't been able to identify it. Any help?
Actually, it turned out there is a bug in testthat 1.0.2 that is already fixed in the github sources (https://github.com/hadley/testthat/commit/99c25fc4efefa012a36d8fc912210ba3452a978d). With this version of testthat all tests in my package pass with no errors.
I'm trying to make a small GUI to make it easier for other people to run a script.
I'm using gWidgets with tcltk on a Windows machine.
I create a simple window like this:
require(gWidgets)
require(gWidgetstcltk)
options(guiToolkit="tcltk")
win <- gwindow(title="This is a window!")
grp <- ggroup(container=win)
lbl <- glabel("Here you can write stuff:", container=grp)
txt <- gedit(text="Stuff", container=grp)
When I run it on a new session i get the error message:
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) :
‘no_items’ is not a valid field or method name for reference class “Entry”
If i rerun after the error i get this:
<simpleError in envRefInferField(x, what, getClass(class(x)), selfEnv): ‘no_items’ is
not a valid field or method name for reference class “Entry”>
Anyone can explain what is going on?
EDIT:
The problem seems to only show up on RStudio and not on RGui.exe.
I'm not such an expert programmer, but I guess it is somehow related with the way RStudio manages the environments.
I guess the question now is more: How do i make this work normally in RStudio?
Traceback:
> traceback()
11: stop(gettextf("%s is not a valid field or method name for reference class %s",
sQuote(field), dQuote(thisClass#className)), domain = NA)
10: envRefInferField(x, what, getClass(class(x)), selfEnv)
9: r5_widget$no_items
8: r5_widget$no_items
7: .length(x#widget, x#toolkit)
6: .length(x#widget, x#toolkit)
5: FUN(X[[3L]], ...)
4: FUN(X[[3L]], ...)
3: lapply(X = X, FUN = FUN, ...)
2: sapply(globalValues, length, USE.NAMES = FALSE) at SessionWorkspace.R#166
1: (function ()
{
globals = ls(envir = globalenv())
globalValues = lapply(globals, function(name) {
get(name, envir = globalenv(), inherits = FALSE)
})
types = sapply(globalValues, .rs.getSingleClass, USE.NAMES = FALSE)
lengths = sapply(globalValues, length, USE.NAMES = FALSE)
values = sapply(globalValues, .rs.valueAsString, USE.NAMES = FALSE)
extra = sapply(globalValues, .rs.valueDescription, USE.NAMES = FALSE)
result = list(name = globals, type = types, len = lengths,
value = values, extra = extra)
result
})()