From 18d17686abd4db371720545f30088d02395bf49d Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Thu, 14 Nov 2024 17:42:25 -0500 Subject: [PATCH] rstudio vs positron --- R/posit.R | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/R/posit.R b/R/posit.R index 1332a961..f3dea736 100644 --- a/R/posit.R +++ b/R/posit.R @@ -1,19 +1,16 @@ -is_posit <- function() { - tryCatch(rstudioapi::isAvailable(), error = function(e) FALSE) +# hack to detect Rstudio vs. Positron +is_rstudio <- function() { + tryCatch(rstudioapi::getThemeInfo(), error = function(e) FALSE) } -is_posit_notebook <- function() { +is_rstudio_notebook <- function() { flag <- FALSE - if (is_posit()) { - ## this returns a .Rmd/.qmd path in Positron, but Positron doesn't support inline tables - ## TODO: this is a very ugly hack: https://github.com/rstudio/rstudioapi/issues/310 - # con <- rstudioapi::getSourceEditorContext()[["path"]] - con <- rstudioapi::getActiveDocumentContext()[["path"]] + # inline doesn't work in Positron + if (is_rstudio()) { + con <- rstudioapi::getActiveDocumentContext()[["path"]] if (isTRUE(grepl("\\.qmd$|\\.Rmd$", con))) { flag <- TRUE } } return(flag) } - -