Basic-Excel-R-Toolkit
Basic-Excel-R-Toolkit copied to clipboard
What is the size limit for the string rc=Application.Run("BERT.Call", cmd)
Is there a limit on the size of the string that you can use when using "BERT.Call".
I'm generating a long string in VBA (517 characters) which causes the application to hang. If I paste the string into the BERT console it works. However when I submit it from VBA it causes an issue.
The example below assumes the library heemod has been called.
The code below works in R studio, and works from the BERT console, but does not work when you assign it to a string and use BERT.Call.
The only work around I can think of is to write the string to a file, and then source the file.
param <- define_parameter(age_init=60, sex=0,age=age_init+markov_cycle,omrPTHR=0.02,omrRTHR=0.02,rrr=0.04,cons=-5.49094,ageC=-0.0367,maleC=0.768536,lambda=exp(cons+ageCage_init+maleCsex),gamma=1.45367786,rrNP1=0.260677,standardRR=1-exp(lambda*((markov_cycle-1)^gamma-markov_cycle^gamma)),np1RR=1-exp(lambdarrNP1((markov_cycle-1)^gamma-markov_cycle^gamma)),sex_cat=ifelse(sex==0,'FMLE','MLE'),mr=get_who_mr(age,sex_cat,country='GBR',local=TRUE),u_SuccessP=0.85,u_RevisionTHR=0.3,u_SuccessR=0.75,c_RevisionTHR=5294)
This has nothing to do with the length of the string. The problem is that the value you are returning includes language constructs (LANGSXP
type) which we can't handle -- this is fine, we ignore them -- but they are named, so we're trying to name values that don't exist. So this is a bug.
Assuming you are not going to manipulate this value in VBA, which I wouldn't recommend anyway, then an immediate workaround is just to return something else, like a boolean, via a new statement:
param <- define_parameter(x,y,z,etc);T
Thank you. I tried your suggestion and it worked. The package that I'm working with in R makes some complicated lists and object that I don't really want to bring back to VBA.
Incidentally you should use BERT.Exec
to execute arbitrary code, and BERT.Call
to call functions with arguments.
Sorry, I was actually using BERT.Exec