-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement citation mechanism (#110)
- Loading branch information
Showing
11 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
tmpCiteEnv = new.env(parent = emptyenv()) | ||
|
||
.suggestCiteMethod = function(x, optional = TRUE) { | ||
assert_that( | ||
is.lcMethod(x) || is.lcModel(x), | ||
is.flag(optional) | ||
) | ||
|
||
cite = getCitation(x) | ||
citeName = paste0('latrend.cited.', class(x)) | ||
skip = getOption(citeName, default = FALSE) | ||
assert_that( | ||
is.flag(skip), | ||
msg = sprintf('Invalid value for option "%s": should be a flag (T/F)', citeName) | ||
) | ||
|
||
if (length(cite) == 0 || exists(citeName, envir = tmpCiteEnv) || optional && skip) { | ||
return() | ||
} | ||
|
||
message( | ||
sprintf( | ||
'Attribution notice: %1$s makes use of external R package(s): | ||
- Run `getCitation(model)` to view how to cite the external package(s) when reporting results. | ||
- To disable this notice, run `options(%2$s = TRUE)`.', | ||
class(x), | ||
citeName | ||
) | ||
) | ||
|
||
assign(citeName, value = TRUE, envir = tmpCiteEnv) | ||
} | ||
|
||
.clearCited = function() { | ||
tmpCiteEnv = new.env(parent = emptyenv()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
test_that('nothing to cite', { | ||
.clearCited() | ||
expect_silent({ | ||
.suggestCiteMethod(testModel1) | ||
}) | ||
|
||
expect_silent({ | ||
.suggestCiteMethod(testModel3) | ||
}) | ||
}) | ||
|
||
|
||
test_that('method citation', { | ||
skip_if_not_installed('kml') | ||
method = lcMethodKML('Y', id = 'Id', time = 'Time', nClusters = 3) | ||
.clearCited() | ||
|
||
options(latrend.cited.lcMethodKML = FALSE) | ||
expect_message({ | ||
.suggestCiteMethod(method) | ||
}, 'lcMethodKML') | ||
|
||
# should not print on the second run | ||
expect_silent({ | ||
.suggestCiteMethod(method) | ||
}) | ||
|
||
# should not print when option is set | ||
.clearCited() | ||
options(latrend.cited.lcMethodKML = TRUE) | ||
expect_silent({ | ||
.suggestCiteMethod(method) | ||
}) | ||
}) |