在構建 JMP 插件時,我經常使用 JMP 到 R 接口, JMP 到 R 自定義插件生成器。 因此,如果您想了解如何開始使用 JSL 連接 JMP 到 R,那麼您來對地方了!
我主張通過示例學習而不是記住 API,所以讓我們從通過 R 往返數據的示例開始,然後回到聯合管理計劃。 您需要將數據從 JMP 發送到 R,在 R 中執行操作,然後將結果返回到 JMP。 因此,您的腳本的主幹應該如下所示:
//initializes the R interfaces
R Init();
//send data to R
R Send(/*name of JMP object you want to send to R, i.e. data table, list, matrix, string, or numeric*/);
//or
R Send File(/*path to the file you want to send here, as a string*/);
//perform calculations in R
R Submit(/*code you want to execute in R here, as a string*/);
//or
R Submit File(/*path to the file that contains the R code you want to execute*/);
//return data from R
varName = R Get(/*name of object you want to return from R*/);
//terminates the R interfaces
R Term();
或者,也許您想在一行中完成所有操作,這相當於R 發送()對於你的變量名一一來說, R 提交()對於您的代碼,以及R 獲取()對於 R 變量一一:
R Execute(/*list of R input var names*/, /*list of R output var names*/, "\[your R code to submit]\");
我見過的一個常見問題是,“兩者之間有什麼區別?” R 發送()和R 提交() ?
R 發送()將數據結構發送到 R — 五個選項是數據表、列表、矩陣、字符串和數字。
R 提交()相比之下,將 R 代碼作為字符串提交給您要執行的 R。 如果代碼不包含引號,則可以將代碼寫為字符串,或者使用以下命令對其進行轉義“\[ 代碼 ]\” 。
一旦你有了這個主幹,一個問題仍然存在:如何以你可以使用的格式獲得 R 輸出?
答案是:視情況而定。
如果要打開從 R 檢索的數據表,可以使用以下命令:
R Get(/*name of R variable that contains data table*/) << new data view;
這將打開 JMP 中的數據表。
如果要在現有 JMP 數據表中追加列,可以使用:
varName = R Get(/*name of R variable that contains list with values*/);
dt << New Column(/*name of new column*/, /*column data type, e.g. Character, Numeric*/, Values(varName));
如果你想展示最多最近生成 R 圖,您可以使用:
R Get Graphics(/*either png or jpg*/);
要在 JMP 窗口中查看此圖像,請使用:
New Window("My Plot", R Get Graphics(/*either png or jpg*/));
還有其他輸出選項,本節介紹了其中一些掌握 JMP 網絡廣播。
需要注意的一個非常重要的事項:在執行諸如R 獲取() ,R 變量名稱必須是 JSL 表達式的名稱(即不是字符串)。 R 獲取(“var”) ,這是不正確的,不等於R 獲取(變量) , 哪個是對的。
最後,我在使用 JMP to R 接口時遇到的一個問題是,我依賴用戶輸入來確定這些函數的參數。 在這種情況下,我會使用評估(解析())運行這些 JMP 到 R 接口命令。 例如:
Eval(Parse(varName || " = R Get(" || userInputValue || ");"));
或者
Eval(Parse("dt << New Column(userInputForColumnName, " || userInputForColumnType || ", Values(" || stringNameOfListVariable || "));"));
除這些之外的其他 JMP 到 R 功能( R 連接() , R 控制()等)可以在腳本索引中找到。
祝你好運! 我很想听聽您的想法聯合管理計劃到下面評論中的 R 接口。