RExcel assumes that arrays have only one underlying scalar type.
You are mixing numbers and strings.
RExcel does not support this.
R also assumes that matrices have just one scalar type.
You can send dataframes with columns of differernt types to R,
but only from a worksheet, not from VBA directly.
You could, however, create 2 columns of different types, transfer them,
and then use cbind or data.frame to combine these columns into a dataframe.



Yaning Zhang wrote:
> Hi, thanks a lot for your reply. The VBA array is obtained by "GetRows"
> method and the following codes would be the equivalent.
> 
> Sub test1()
>     Dim arrProject As Variant
>     arrProject(1,1)="const"
>     arrProject(1,2)=12
>     arrProject(2,1)="price"
>     arrProject(2,2)=14
>     RInterface.StartRServer
>     RInterface.PutArrayFromVBA ("AsVariant", arrProject)
>     RInterface.StopRServer
> End Sub
>     
> I would appreciate any advice.
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Erich
> Neuwirth
> Sent: Thursday, November 29, 2007 4:00 PM
> To: R (D)COM and RExcel server related issues
> Subject: Re: [Rcom-l] Put Array from VBA-query about enviroment
> 
> It would help if you gave the exact command producing this error
> message.
> 
> 
> 
> The following code works:
> 
> Sub PutArrayTest()
>     Dim MyVar As Variant
>     Dim MyArray(1 To 2, 1 To 2)
>     Dim MyVarArray(1 To 2, 1 To 2)
>     MyArray(1, 1) = 11
>     MyArray(1, 2) = 12
>     MyArray(2, 1) = 13
>     MyArray(2, 2) = 14
>     MyVarArray(1, 1) = 11
>     MyVarArray(1, 2) = 12
>     MyVarArray(2, 1) = 13
>     MyVarArray(2, 2) = 14
>     MyVar = MyArray
>     RInterface.StartRServer
>     RInterface.PutArrayFromVBA "AsVariant", MyVar
>     RInterface.PutArrayFromVBA "AsArray", MyArray
>     RInterface.PutArrayFromVBA "AsVarArray", MyVarArray
>     RInterface.StopRServer
> End Sub
> 
> After running this in Excel, you can look at the variables
> AsVariant, AsArray and AsVarArray in R and will see their values.
> 
> 
> 
> Yaning Zhang wrote:
>> Hello, I guess it is useful to point out the error message in R
> console
>> is like this "Error in eval(expr, envir, enclos) : object "rvariable"
>> not found.
>>
>> I do not quite understand what this means.
>>
>>  
>>
>>
> ------------------------------------------------------------------------
>> *From:* [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] *On Behalf Of *Yaning
> Zhang
>> *Sent:* Thursday, November 29, 2007 1:27 PM
>> *To:* R (D)COM and RExcel server related issues
>> *Subject:* RE: [Rcom-l] Put Array from VBA
>>
>>  
>>
>> Yes, its type is variant. I checked the arrProject and it is correct.
>>
>>  
>>
>>
> ------------------------------------------------------------------------
>> *From:* [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] *On Behalf Of
>> [EMAIL PROTECTED]
>> *Sent:* Thursday, November 29, 2007 12:57 PM
>> *To:* R (D)COM and RExcel server related issues
>> *Subject:* Re: [Rcom-l] Put Array from VBA
>>
>>  
>>
>> Try making arrProject of type variant.
>>
>>
> ------------------------------------------------------------------------
>>  ----- Original Message -----
>> *  From: *"Yaning Zhang" [EMAIL PROTECTED]
>> *  Sent: *11/29/2007 12:15 PM GMT
>> *  To: *"R (D)COM and RExcel server related issues"
>> <rcom-l@mailman.csd.univie.ac.at>
>> *  Subject: *RE: [Rcom-l] Put Array from VBA
>>
>>  
>>
>> Thanks for your reply. I tried, but it does not work, still saying
> could
>> not find the object "rvariable" if I call it the R console.
>>
>>  
>>
>>
> ------------------------------------------------------------------------
>> *From:* [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] *On Behalf Of
>> [EMAIL PROTECTED]
>> *Sent:* Thursday, November 29, 2007 12:13 PM
>> *To:* R (D)COM and RExcel server related issues
>> *Subject:* Re: [Rcom-l] Put Array from VBA
>>
>>  
>>
>> Try putting rvariable is quotes:
>>
>>
>> Call Rinterface.PutArrayFromVBA("rvariable", arrProject)
>>
>>
> ------------------------------------------------------------------------
>>  ----- Original Message -----
>> *  From: *"Yaning Zhang" [EMAIL PROTECTED]
>> *  Sent: *11/29/2007 11:28 AM GMT
>> *  To: *"R (D)COM and RExcel server related issues"
>> <rcom-l@mailman.csd.univie.ac.at>
>> *  Subject: *[Rcom-l] Put Array from VBA
>>
>>  
>>
>> Hello everyone,
>>
>>  
>>
>> I would like to assign the contents of a VBA array to an R variable,
> and
>> I am using the following function. "arrProject" is a VBA array.
>>
>>  
>>
>> Call Rinterface.PutArrayFromVBA(rvariable, arrProject)
>>
>>  
>>
>> The first question is Do I need to define the "rvariable" name in VBA
>> using "Dim rvariable As String" or any other type of variable? It
> seems
>> like if I do not define it, it will comes out the error message saying
>> variable undefined. Then after naming it, I call "rvariable" in the R
>> console, but it says object not found.
>>
>>  
>>
>> Could anyone give me some advice? Many thanks.
>>
>>  
>>
>> Yaning Zhang
>>
>>  
>>
>>
>>
> ------------------------------------------------------------------------
>> _______________________________________________
>> Rcom-l mailing list
>> Rcom-l@mailman.csd.univie.ac.at
>> http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
>> More information (including a Wiki) at http://rcom.univie.ac.at
> 
> 
> _______________________________________________
> Rcom-l mailing list
> Rcom-l@mailman.csd.univie.ac.at
> http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
> More information (including a Wiki) at http://rcom.univie.ac.at
> _______________________________________________
> Rcom-l mailing list
> Rcom-l@mailman.csd.univie.ac.at
> http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
> More information (including a Wiki) at http://rcom.univie.ac.at
> 
> 

_______________________________________________
Rcom-l mailing list
Rcom-l@mailman.csd.univie.ac.at
http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l
More information (including a Wiki) at http://rcom.univie.ac.at

Reply via email to