posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.77k stars 84 forks source link

R console freezes after assigning variable from file #5270

Closed ohmstead closed 5 days ago

ohmstead commented 1 week ago

System details:

Positron and OS details:

Positron Version: 2024.11.0 (Universal) build 116 Code - OSS Version: 1.93.0 Commit: 8b1688ababfa228db515a739050c466f3bb3089f Date: 2024-10-28T02:50:56.075Z (1 wk ago) Electron: 30.4.0 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Darwin arm64 23.5.0

Interpreter details:

R 4.4.1

Describe the issue:

The R console freezes and must be restarted after assigning data loaded from an .Rds file to a variable. The console behaves normally if I load the .Rds file without assigning it to a variable.

Steps to reproduce the issue:

Commands pasted in the R console:

> library(Seurat)
Loading required package: SeuratObject
Loading required package: sp
‘SeuratObject’ was built under R 4.4.0 but the current version is 4.4.1; it is recomended that you reinstall
‘SeuratObject’ as the ABI for R may have changed

Attaching package: ‘SeuratObject’

The following objects are masked from ‘package:base’:

    intersect, t

> readRDS('04-analysis/seurat.Rds')
An object of class Seurat 
85045 features across 10443 samples within 2 assays 
Active assay: SCT (28035 features, 3000 variable features)
 3 layers present: counts, data, scale.data
 1 other assay present: RNA
 2 dimensional reductions calculated: pca, umap
> nuclei <- readRDS('04-analysis/seurat.Rds')
> print('test')

Expected or desired behavior:

I expect to be able to see 'test' printed in the console after assigning the data loaded from seurat.Rds to the nuclei variable. However, the R console remains busy in perpetuity when executing the command after nuclei <- readRDS('04-analysis/seurat.Rds')

The command (in this example, print('test') cannot be interrupted, only Force Quit.

If I don't assign the output to a variable, everything works just fine:

> readRDS('04-analysis/seurat.Rds')
An object of class Seurat 
85045 features across 10443 samples within 2 assays 
Active assay: SCT (28035 features, 3000 variable features)
 3 layers present: counts, data, scale.data
 1 other assay present: RNA
 2 dimensional reductions calculated: pca, umap
> print('hi')
[1] "hi"

Were there any error messages in the UI, Output panel, or Developer Tools console?

Developer Tools Console output:

INFO Restarting session 'Session R 4.4.1 (r-7ef8b7eb) from runtime 41c840486bc99a24fd1c1245762ae18f (language: R name: R 4.4.1 version: 4.4.1)' (Source: Restart requested from activity in the Console tab)
workbench.desktop.main.js:130677  INFO Starting session for language runtime 41c840486bc99a24fd1c1245762ae18f (language: R name: R 4.4.1 version: 4.4.1) (Source: 'Restart Interpreter' command invoked)
workbench.desktop.main.js:130667 DEBUG [Ext host 0] Runtime manager for 'R 4.4.1': true
workbench.desktop.main.js:130687  WARN Already attached to session, disposing existing listeners before reattaching: r-3bab00ed
workbench.desktop.main.js:130677  INFO Creating positron.variables client 'positron-variables-r-4-3e51c0b9'...
workbench.desktop.main.js:130687  WARN Ignoring call to requestRefresh; client is not available.
workbench.desktop.main.js:130677  INFO Creating positron.ui client 'positron-ui-r-5-abfa43d3'...
workbench.desktop.main.js:130677  INFO Creating positron.variables client 'positron-variables-r-6-cf1122b5'...
workbench.desktop.main.js:130677  INFO Creating positron.help client 'positron-help-r-7-62f13e0c'...
workbench.desktop.main.js:130687  WARN Ignoring unknown client type 'positron.dap' for client 'positron-dap-r-3-f117b4c7'
workbench.desktop.main.js:130667 DEBUG [perf] SLOW task detected (324ms) but renderer profiling is disabled via 'application.experimental.rendererProfiling'
workbench.desktop.main.js:130667 DEBUG Comments: URIs of continue on comments to add to storage .
2workbench.desktop.main.js:130667 DEBUG Comments: URIs of continue on comments to add to storage .
workbench.desktop.main.js:130667 DEBUG Comments: URIs of continue on comments to add to storage .
workbench.desktop.main.js:130667 DEBUG Comments: URIs of continue on comments to add to storage .
workbench.desktop.main.js:130667 DEBUG Comments: URIs of continue on comments to add to storage .
testlabauto commented 6 days ago

Hello! Thank you for using positron.

By chance can you create a simple repro case with an attached dummy rds file? This would greatly help us in getting to the bottom of this issue.

jthomasmock commented 6 days ago

Seems I can reprex this with the example data, but I think that it's just a long/slow operation? After about 1 minute the console is functional again.

# Need to do this first
# devtools::install_github('satijalab/seurat-data')
# SeuratData::InstallData("pbmc3k")
library(Seurat)
library(SeuratData)

pbmc3k.final <- LoadData("pbmc3k", type = "pbmc3k.final")

print("hi")

Running gives the below:

> library(Seurat)
Loading required package: SeuratObject
Loading required package: sp

Attaching package: 'SeuratObject'

The following objects are masked from 'package:base':

    intersect, t

> library(SeuratData)
── Installed datasets ─────────────────────────────────────────── SeuratData v0.2.2.9001 ──
✔ pbmc3k 3.1.4                               

─────────────────────────────────────────── Key ───────────────────────────────────────────
✔ Dataset loaded successfully
❯ Dataset built with a newer version of Seurat than installed
❓ Unknown version of Seurat installed

Warning message:
input string '<b7>' cannot be translated to UTF-8, is it valid in 'ANSI_X3.4-1968'? 
Warning message:
input string '<b7>' cannot be translated to UTF-8, is it valid in 'ANSI_X3.4-1968'? 
Warning message:
input string '<b7>' cannot be translated to UTF-8, is it valid in 'ANSI_X3.4-1968'? 
> pbmc3k.final <- LoadData("pbmc3k", type = "pbmc3k.final")
Validating object structure
Updating object slots
Ensuring keys are in the proper structure
Updating matrix keys for DimReduc 'pca'
Updating matrix keys for DimReduc 'umap'
Warning: Assay RNA changing from Assay to Assay
Warning: Graph RNA_nn changing from Graph to Graph
Warning: Graph RNA_snn changing from Graph to Graph
Warning: DimReduc pca changing from DimReduc to DimReduc
Warning: DimReduc umap changing from DimReduc to DimReduc
Ensuring keys are in the proper structure
Ensuring feature names don't have underscores or pipes
Updating slots in RNA
Updating slots in RNA_nn
Setting default assay of RNA_nn to RNA
Updating slots in RNA_snn
Setting default assay of RNA_snn to RNA
Updating slots in pca
Updating slots in umap
Setting umap DimReduc to global
Setting assay used for NormalizeData.RNA to RNA
Setting assay used for FindVariableFeatures.RNA to RNA
Setting assay used for ScaleData.RNA to RNA
Setting assay used for RunPCA.RNA to RNA
Setting assay used for JackStraw.RNA.pca to RNA
No assay information could be found for ScoreJackStraw
Setting assay used for FindNeighbors.RNA.pca to RNA
No assay information could be found for FindClusters
Setting assay used for RunUMAP.RNA.pca to RNA
Validating object structure for Assay 'RNA'
Validating object structure for Graph 'RNA_nn'
Validating object structure for Graph 'RNA_snn'
Validating object structure for DimReduc 'pca'
Validating object structure for DimReduc 'umap'
Object representation is consistent with the most current Seurat version
Warning: Assay RNA changing from Assay to Assay5
Warning messages:
1: Adding a command log without an assay associated with it 
2: Adding a command log without an assay associated with it 
ZhimingYe commented 6 days ago

@jthomasmock I can provide some more information. It's just similar to #4313, which is related to #3628, a known issue. The pbmc3k dataset only contains a sparse matrix with ~20000 rows and ~3000 columns, in RStuido or R command line interface, this won't take 1 minute. I’ve been troubled by this issue for a long time. So far, Positron is essentially a pure Python IDE for me, and almost none of the R functionalities are usable because of this, in this area. 😊

juliasilge commented 5 days ago

Ah, nice work @ZhimingYe! This is in fact the same as https://github.com/posit-dev/positron/issues/3628; I've added the example there so we can track it as an additional example.

ohmstead commented 2 days ago

You are all rockstars! Sorry it took a few days for me to return to this.

@jthomasmock Importantly, in your reprex, the operation print("hi") never prints to console because the console is still hung up.

@ZhimingYe I think you're totally correct this is the same issue.

Appreciate everybody's input on this. I agree with @ZhimingYe that this is currently a big limitation for Positron in bioinformatics... I would love to use it, but can't at this point because of this issue.