Basic-Excel-R-Toolkit icon indicating copy to clipboard operation
Basic-Excel-R-Toolkit copied to clipboard

Returning dataframe with row and column names crashes Excel in BERT 1.64

Open tunguyen71 opened this issue 7 years ago • 4 comments

Dear BERT developers

I have been enjoying using BERT for quite a while and recently downloaded version 1.64. Unfortunately, I am seeing a number of problems including Excel crashes.

Specifically I am returning a dataframe to VBA by calling BERT.Exec. If the dataframe has row and column names then I see a crash. Here's an example:

Function TestBERT()
    'Code below crashes Excel with BERT 1.64 but not with BERT 1.63
    Dim RCode, Res
    RCode = "MyDF<-as.data.frame(cbind(c(""Foo"",""Bar""),c(1,2)));colnames(MyDF)<-c(""a"",""b"");rownames(MyDF)<-c(""1R"",""2R"");MyDF"
    Res = Application.Run("BERT.Exec", RCode)
End Function

In the case when there are no row and column names to the dataframe, I don't see a crash, but the data returned to VBA has a very complex structure. BERT 1.64 returns an array of arrays (a hard thing to work with in VBA) whereas 1.63 returned an array of "singletons". That's easiest to describe with the VBA Locals window. The image below is with BERT 1.64. image

Whereas with BERT 1.63 the return is much simpler and easier to work with: bert163picture

I see from your release comments that you made changes to the handling of "lists of lists". A dataframe is of course a list of lists, but on the other hand, a dataframe should surely map to a simple two-dimensional array in Excel.

Do you think you could fix the crash bug and revert to the BERT 1.63 handling of dataframes?

Thanks!

Tu

tunguyen71 avatar Feb 22 '18 17:02 tunguyen71

The nested arrays are unintentional, that probably arose as part of simplifying some of the type conversion code. The next version is a complete rewrite and I can confirm that it's going to return simpler array structures for data frames.

Given that it might take a while to get to the 2.0 release, I may look at fixing this in a patch release.

duncanwerner avatar Feb 22 '18 18:02 duncanwerner

Do you want row/column names in a returned frame? We go back and forth on this.

duncanwerner avatar Feb 22 '18 18:02 duncanwerner

Hi Duncan Thanks for your reply (and by the way Tu is a colleague of mine here at Solum Financial).

In response to your question about row/column names returned in a frame, one possibility that comes to mind is to return them to the VBA side if they are not NULL on the R side. Of course, that's a change that might break some of your users' existing code (but if you have "gone back and forth" then perhaps they're used to that!), but it would give a nice level of control without adding some clumsy argument to BERT.Exec.

So suppose MyDataframe has row and column names then Application.Run("BERT.Exec","MyDataframe") would return row and column headers, but Application.Run("BERT.Exec","Tmp<-MyDataframe;rownames(Tmp)<-NULL;colnames(Tmp)<-NULL;Tmp") would not return row and column headers.

Philip

PGS62 avatar Feb 23 '18 09:02 PGS62

I have a list called Extras in which i try to ADD an EXTRA row to the list. I tried to run the code below in BERT:

nxe[nrow(nxe)+1,] = Extras[which(nxe[,1] == "sample"),]

the error i get in the BERT console:

nxe[nrow(nxe)+1,] = nxe[which(nxe[,1] == "sample"),] Error in [<-(*tmp*, nrow(nxe) + 1, , value = list()) : subscript out of bounds

Whats the workaround on this issue?

KhotsoRamoreboli avatar Dec 14 '22 10:12 KhotsoRamoreboli