Skip to content

guard against export crashing during debugging? #47

@klin333

Description

@klin333

Hi,

Love the export capability. However, when interactively debugging a script that's used as a module, the export() call crashes and I'm forced to manually comment out the export calls during debug sessions. Could we somehow safely avoid the crash?

for example script_to_debug.R

export("foo")

foo <- function(x) {
  x
}

sourcing this script in an interactive R session crashes with:

> source("xxxxx/script_to_debug.R", echo=TRUE)

> export("foo")
Error in get(exportNameWithinModule(), envir = envir) :
object '.__exports__' not found

I suppose a quick fix is something like this in modules export.R

export <- function(..., where = parent.frame()) {
  if (!exists(exportNameWithinModule(), envir = where)) {
    # not in a module, likely called from user sourcing a script during debug session. do nothing.
    return(invisible(NULL))
  }
  ...
}

test-export.R still runs fine. However I have no idea of the implications...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions