R/addin.R

Defines functions add_in_runs_info add_in_guild_view add_in_guild_run

add_in_guild_run <- function() {
  editor_context <- rstudioapi::getSourceEditorContext()
  editor_path <- editor_context$path
  if (isTRUE(nzchar(editor_path))) {
    rstudioapi::documentSaveAll()
    normalized_wd <- normalizePath(getwd(), winslash = "/", mustWork = FALSE)
    normalized_editor_path <- normalizePath(editor_path, winslash = "/", mustWork = FALSE)
    if (grepl(paste0("^", normalized_wd), normalized_editor_path))
      editor_path <- sub(paste0("^", normalized_wd, "[/\\\\]"), "", normalized_editor_path)
    rstudioapi::sendToConsole(sprintf('guildai::guild_run("%s")', editor_path))
  } else {
    message("Unable to perform training run (active source file is not an R script)")
  }
}


add_in_guild_view <- function() {
  rstudioapi::sendToConsole("guildai::guild_view()")
}

add_in_runs_info <- function() {
  rstudioapi::sendToConsole(
    'View(tidyr::unpack(guildai::runs_info(), c(flags, scalars), names_sep = "$"), title = "runs_info()")'
  )
}

Try the guildai package in your browser

Any scripts or data that you put into this service are public.

guildai documentation built on March 7, 2023, 5:32 p.m.