Skip to content

Conversation

@juliasilge
Copy link
Contributor

Addresses posit-dev/positron#9933

With this change, I see results like this in the Positron console:

> .Platform
$OS.type
[1] "unix"

$file.sep
[1] "/"

$dynlib.ext
[1] ".so"

$GUI
[1] "Positron"

$endian
[1] "little"

$pkgType
[1] "mac.binary.big-sur-arm64"

$path.sep
[1] ":"

$r_arch
[1] ""

And results like this in an R session running in an integrated terminal in Positron (the same as RStudio):

> .Platform
$OS.type
[1] "unix"

$file.sep
[1] "/"

$dynlib.ext
[1] ".so"

$GUI
[1] "X11"

$endian
[1] "little"

$pkgType
[1] "mac.binary.big-sur-arm64"

$path.sep
[1] ":"

$r_arch
[1] ""

Does SessionMode::Console really just mean only in Positron? Is there some better way for ark to know when it's running in Positron at initialization?

Comment on lines 623 to 635
// Set .Platform$GUI to "Positron" for console sessions only
if session_mode == SessionMode::Console {
let result = harp::parse_eval_global(r#"
unlockBinding(".Platform", baseenv())
.Platform$GUI <- "Positron"
lockBinding(".Platform", baseenv())
"#);
match result {
Ok(_) => log::info!("Set .Platform$GUI to 'Positron' for console session"),
Err(err) => log::warn!("Failed to set .Platform$GUI: {err:?}"),
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the best approach is, but this one is at least easy to reason about.

Some other approaches I tried out included:

  • Do something like r_symbol!(".Platform") in Rust and find the GUI element. I like that this doesn't involve executing R code during some initialization step, but you still have to lock/unlock (just at the C level).
  • Do the locking/unlocking in startup.R. This feels like a better place to run such R code, but I'm not sure we can check session mode there and the other options there are more user-facing.

RStudio does it here, which is not exactly the same but similar in that in happens post-initialization:
https://github.com/rstudio/rstudio/blob/5381a9a4363eae00007fd170302fa8a5c93050b5/src/cpp/r/R/Options.R#L126

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer this to be in an R file, maybe in modules/positron/positron.R. Then you can use:

.Platform <- base::.Platform
.Platform$GUI <- "Positron"
env_bind_force(baseenv(), ".Platform", .Platform)

@juliasilge juliasilge requested a review from lionel- December 3, 2025 01:16
Copy link
Contributor

@lionel- lionel- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to set GUI to something else than "Positron" when Ark runs with another frontend. To determine that, we could detect whether Sys.getenv("POSITRON_VERSION") is defined. If not, we'd set GUI to "Ark". What do you think?

Comment on lines 623 to 635
// Set .Platform$GUI to "Positron" for console sessions only
if session_mode == SessionMode::Console {
let result = harp::parse_eval_global(r#"
unlockBinding(".Platform", baseenv())
.Platform$GUI <- "Positron"
lockBinding(".Platform", baseenv())
"#);
match result {
Ok(_) => log::info!("Set .Platform$GUI to 'Positron' for console session"),
Err(err) => log::warn!("Failed to set .Platform$GUI: {err:?}"),
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer this to be in an R file, maybe in modules/positron/positron.R. Then you can use:

.Platform <- base::.Platform
.Platform$GUI <- "Positron"
env_bind_force(baseenv(), ".Platform", .Platform)

@juliasilge
Copy link
Contributor Author

Ah, I am experimenting and it looks like the .R files in modules/positron/ are only evaluated in the Positron console? Not R sessions in integrated terminals? That will work well then.

@juliasilge
Copy link
Contributor Author

This is a much better approach. Thanks, @lionel-!

@juliasilge juliasilge requested a review from lionel- December 3, 2025 16:28
Comment on lines 8 to 9
.Platform <- base::.Platform
.Platform$GUI <- "Positron"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it "Ark" if Sys.getenv("POSITRON") is not set? Or leave the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand, files in modules/positron get evaluated outside of Positron? All the options in options.R, etc? Can you explain a bit more about this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #588 is about this.

Copy link
Contributor

@lionel- lionel- Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand, files in modules/positron get evaluated outside of Positron? All the options in options.R, etc? Can you explain a bit more about this?

They do because some of the files in there provide essential Ark functionality, for instance regarding error handling.

Maybe the folder really should be called ark? Or maybe we should split ark from the positron folder and the latter would only get sourced in Positron? That would be a nice way to easily differentiate generic and positron-specific functionality.

We could then have a .ark. prefix in addition to the .ps. prefix, for symbols exported from the ark folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and checked the env var in 1b11568, ahead of improvements like that.

@juliasilge juliasilge requested a review from lionel- December 3, 2025 17:22
Co-authored-by: Lionel Henry <lionel.hry@proton.me>
@juliasilge juliasilge merged commit 401cf71 into main Dec 3, 2025
8 checks passed
@juliasilge juliasilge deleted the platform-gui-console-positron branch December 3, 2025 18:19
@github-actions github-actions bot locked and limited conversation to collaborators Dec 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants