Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/safe_assign.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ safe_assign <- function(x, value, pos = -1, envir = as.environment(pos), inherit
{
if (x %in% ls(envir, all.names = TRUE) &&
!identical(environment(envir[[x]]), environment(value)))
stop("Cannot assign name to different value in the given environment. Name already in use.",
stop(sprintf("Cannot assign name `%s` to different value in the given environment. Name already in use.",
x),
call. = FALSE)

assign(x, value, pos, envir, inherits)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_import/test_from.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ test_that("Imports from modules work", {
cleanup_environment()
})

test_that("Conflicting imports throw error containing conflicting name", {
expect_error ( fun1() )
expect_silent( import::from(module_base.R, fun1) )
expect_error ( import::from(module_hidden_objects.R, fun1) )
expect_error ( import::from(module_hidden_objects.R, fun1), ".*fun1.*" )
cleanup_environment()
})

test_that("Subsequent imports from modules work", {
expect_error ( fun1() )
expect_error ( fun7() )
Expand Down