emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
626 stars 161 forks source link

[patch] Handling of long expression in ess-watch #1188

Closed DJJ88 closed 2 years ago

DJJ88 commented 2 years ago

Hello,

I noticed that R watch cannot handle long expression properly. It breaks long expression with @--- for some reasons. I admit that I don't fully understand why, but I have tracked it down to .ess_watch_eval.

Below is a dummy example to reproduce the error, but we could imagine to have in real life a data.frame with 4 or 5 colums.

df <-   data.frame(really_really_really_really_really_really_really_really_long_name=1:10,b=letters[1:10])

then in R watch if we add the following new expression in R watch (ess-watch)

subset(df,really_really_really_really_really_really_really_really_long_name==10)

After the expression is loaded in R it becomes

subset(df, really_really_really_really_really_really_really_really_long_name == @---:     10) 

The problem is that, after this expression we cannot enter any new expression as R complains because of a syntax error.

After the patch we have

subset(df, really_really_really_really_really_really_really_really_long_name ==      10) 

We still have extra space but R does not complain.


From 727ea9263d9043850dbda59d87cf02e54fbb793c Mon Sep 17 00:00:00 2001
From: Jeremie Juste <djj@debian-BULLSEYE-live-builder-AMD64>
Date: Sat, 12 Feb 2022 23:17:17 +0100
Subject: [PATCH] * etc/ESSR/R/debug.R: Fix error for long expression in  ess-watch

debug.R (.ess_watch_eval): remove "@---" from long R expression when
loading the expression in R.
---
 etc/ESSR/R/debug.R | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/etc/ESSR/R/debug.R b/etc/ESSR/R/debug.R
index a4fcf638..3f516afa 100644
--- a/etc/ESSR/R/debug.R
+++ b/etc/ESSR/R/debug.R
@@ -163,7 +163,7 @@
         for(i in seq_along(exps)) {
             cat('\n@---- ', .essWEnames[[i]], ' ',
                 rep.int('-', max(0, 35 - nchar(.essWEnames[[i]]))), '-@\n', sep = '')
-            cat(paste('@---:', deparse(exps[[i]][[1]])), ' \n', sep = '')
+            cat(deparse(exps[[i]][[1]]), '\n', sep = '')
             tryCatch(print(eval(exps[[i]],
                                 envir = .parent_frame)),
                      error = function(e) cat('Error:', e$message, '\n' ),
-- 
2.30.2
vspinu commented 2 years ago

Thanks for bringing it up. It happens because during printing expressions are split across multiple lines. Removing @--- marker would not work because on the elisp side it is used to identify expressions. I have fixed this by setting a very large width option to avoid the division.