rstudio / rstudio

RStudio is an integrated development environment (IDE) for R
https://posit.co/products/open-source/rstudio/
Other
4.6k stars 1.08k forks source link

Stan features (autocompletion, document outline, etc.) not working. #14873

Open XavierLaRochelle opened 2 weeks ago

XavierLaRochelle commented 2 weeks ago

System details

RStudio Edition : Desktop
RStudio Version : 2024.04.1+748
OS Version      : 13.6.1 (22G313)
R Version       : 4.4.0 (2024-04-24)

Steps to reproduce the problem

1 - Open a new .stan file. 2 - Write the beginning of a stan function like "norm" for "normal_lpdf()"

The autocompletion doesn't show up.

Describe the problem in detail

Back in 2018, it was announced in this blog post from the posit team that new stan related features would be implemented in Rstudio v1.2. I recently updated my Rstudio and I should be up to date on the latest features but things like stan autocompletion and document outline still does not work. I can't find any info online as to why it wouldn't have been implemented by now so I'm wondering if it's a problem on my end.

Describe the behavior you expected

For the example described above, an autocompletion dropdown menu should show up like it does for base R but it does not.

kevinushey commented 2 weeks ago

Do you have the rstan package installed? RStudio requires this package to be installed in order to provide code completions in Stan files.

Screenshot 2024-06-21 at 11 16 31 AM
XavierLaRochelle commented 2 weeks ago

Yes I have it installed. It's the latest version. Screenshot 2024-06-21 at 2 21 28 PM And still no completion : Screenshot 2024-06-21 at 2 22 13 PM

kevinushey commented 2 weeks ago

Do you also see this in the latest RStudio release (2024.04.2)? I think you may be bumping into an issue that was fixed in the most recent patch release.

XavierLaRochelle commented 2 weeks ago

I re-installed RStudio and I am now on version 2024.4.2.764. Autocompletion is not working still.

kevinushey commented 2 weeks ago

Strange; it seems to be working on my side (tested with both the CRAN release 2.32.6 and dev version 2.35.0.9000).

Screenshot 2024-06-21 at 1 54 21 PM

What does executing this give you?

str(.rs.stan.rosetta())

For example, I see:

> str(.rs.stan.rosetta())
'data.frame':   627 obs. of  4 variables:
 $ StanFunction: chr  "abs" "acos" "acosh" "add" ...
 $ RFunction   : chr  "abs" "acos" "acosh" "+" ...
 $ Arguments   : chr  "(T);(complex)" "(T);(int)" "(T);(int)" "(int, T)" ...
 $ ReturnType  : chr  "T;real" "T;real" "T;real" "T" ...

Similarly, what do you see for:

str(.rs.rpc.stan_get_completions("normal"))

I see:

> str(.rs.rpc.stan_get_completions("normal"))
List of 14
 $ token                          : chr "normal"
 $ results                        : chr [1:9] "normal_ccdf_log" "normal_cdf" "normal_cdf_log" "normal_id_glm_lpdf" ...
 $ packages                       : chr [1:9] "function" "function" "function" "function" ...
 $ quote                          : logi [1:9] FALSE FALSE FALSE FALSE FALSE FALSE ...
 $ type                           : num [1:9] 6 6 6 6 6 6 6 6 6
 $ meta                           : chr [1:9] "(real, real, T);(vector, vector, vector)" "(real, real, T);(vector, vector, vector)" "(real, real, T);(vector, vector, vector)" "(real, matrix, real, vector, T);(vector, row_vector, vector, vector, vector)" ...
 $ fguess                         : chr ""
 $ excludeOtherCompletions        : 'rs.scalar' logi FALSE
 $ excludeOtherArgumentCompletions: 'rs.scalar' logi FALSE
 $ overrideInsertParens           : 'rs.scalar' logi FALSE
 $ cacheable                      : 'rs.scalar' logi TRUE
 $ helpHandler                    : NULL
 $ language                       : 'rs.scalar' chr "R"
 $ context                        : num [1:9] 0 0 0 0 0 0 0 0 0

(these are both functions used behind the scenes by RStudio when retrieving completions for Stan files.)

XavierLaRochelle commented 2 weeks ago

I get the same thing as you for both functions : Screenshot 2024-06-21 at 4 59 19 PM

My "about Rstudio" window looks weird however :

Screenshot 2024-06-21 at 5 00 18 PM I don't know if that's a clue. I have no idea when this started but I recall it wasn't like that before.

kevinushey commented 2 weeks ago

Thanks! I'm surprised that it's still not working on your side.

Last thing... can you confirm that the Stan file you have open has the filetype Stan at the bottom right? Also, does it make a difference if you've already saved the file, versus working in an unsaved file?

Screenshot 2024-06-21 at 2 27 03 PM
XavierLaRochelle commented 2 weeks ago

Yes it's a Stan file : Screenshot 2024-06-21 at 5 29 08 PM I've tried saving and it doesn't change anything as far as I can tell. It's really weird behavior indeed.

ronblum commented 2 weeks ago

@XavierLaRochelle Does rstan load properly? I needed to first install matrixStats which was missing.

> library(rstan)
Loading required package: StanHeaders
Error: package or namespace load failed for ‘rstan’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘matrixStats’

Once I installed it, everything worked properly.

gtritchie commented 1 week ago

Regarding earlier comment about:

"My "about Rstudio" window looks weird however :

That's a known issue. On macOS the RStudio/About RStudio menu shows that smaller About dialog; use Help/About RStudio to see the full dialog. See also: https://github.com/rstudio/rstudio/issues/10571

XavierLaRochelle commented 1 week ago

@ronblum I don't have this problem. Rstan's loading messages looks normal to me :

> library(rstan)
Loading required package: StanHeaders

rstan version 2.32.6 (Stan version 2.32.2)

For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
change `threads_per_chain` option:
rstan_options(threads_per_chain = 1)

Plus, I have the matrixStats package downloaded : Screenshot 2024-06-27 at 2 12 44 PM

@gtritchie Thanks for the info!