. Net calls the R language and. net calls the r language.
/// Load the self-written R Language Algorithm Library public List <double> GetZTFB (double [] data) {List <double> par = new List <double> (); try {// call the R Language Algorithm REngine. setEnvironmentVariables (); REngine engine = REngine. getInstance (null, true, null, null); NumericVector x = engine. createNumericVector (data); engine. setSymbol ("x", x); string path = System. windows. forms. application. startupPath + "\ R_File \ ztfb. R "; path =" source (\ "" + path + "\") "; path = path. replace ("\", "\"); // this step is crucial; otherwise, an error is reported. evaluate (path); engine. evaluate ("a <-ztfb (x)"); // engine. evaluate (@ "normal <-function (theta) {// mu <-theta [1] // sigma <-theta [2] // n <-length (x) // logL <--0.5 * n * log (2 * pi)-n * log (sigma)-sum (0.5 * (x-mu) ^ 2/sigma ^ 2) // return (-logL) //} // a <-nlminb (c (0, 1), normal) "); NumericVector a = engine. evaluate ("a $ par [1]"). asNumeric (); NumericVector B = engine. evaluate ("a $ par [2]"). asNumeric (); par. add (Convert. toDouble (a [0]); par. add (Convert. toDouble (B [0]);} catch (Exception ex) {throw new Exception (ex. message);} return par;} // load the R language download library public List <double> GetZTFB (double [] data) {List <double> par = new List <double> (); try {// call the R Language Algorithm REngine. setEnvironmentVariables (); REngine engine = REngine. getInstance (null, true, null, null); // load the R language library engine. evaluate ("library (\" bit \ ", lib. loc = \ "C:/Program Files/R/R-3.3.2/library \") ") NumericVector x = engine. createNumericVector (data); engine. setSymbol ("x", x); string path = System. windows. forms. application. startupPath + "\ R_File \ ztfb. R "; path =" source (\ "" + path + "\") "; path = path. replace ("\", "\"); // this step is crucial; otherwise, an error is reported. evaluate (path); engine. evaluate ("a <-ztfb (x)"); // engine. evaluate (@ "normal <-function (theta) {// mu <-theta [1] // sigma <-theta [2] // n <-length (x) // logL <--0.5 * n * log (2 * pi)-n * log (sigma)-sum (0.5 * (x-mu) ^ 2/sigma ^ 2) // return (-logL) //} // a <-nlminb (c (0, 1), normal) "); NumericVector a = engine. evaluate ("a $ par [1]"). asNumeric (); NumericVector B = engine. evaluate ("a $ par [2]"). asNumeric (); par. add (Convert. toDouble (a [0]); par. add (Convert. toDouble (B [0]);} catch (Exception ex) {throw new Exception (ex. message);} return par ;}