Révision 1766
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RWorkspace.java (revision 1766) | ||
---|---|---|
1509 | 1509 |
} |
1510 | 1510 |
|
1511 | 1511 |
/** |
1512 |
* Casts the specified REXP to a displayable object. |
|
1513 |
* @param rexp |
|
1514 |
* @return |
|
1515 |
*/ |
|
1516 |
public Object getCastedREXP(REXP rexp) { |
|
1517 |
try { |
|
1518 |
if (rexp instanceof org.rosuda.REngine.REXPString) { |
|
1519 |
if (rexp.isVector()) { |
|
1520 |
return StringUtils.join(rexp.asStrings(), ", "); //$NON-NLS-1$ |
|
1521 |
} |
|
1522 |
else { |
|
1523 |
return rexp.asString(); |
|
1524 |
} |
|
1525 |
} |
|
1526 |
else if (rexp instanceof org.rosuda.REngine.REXPDouble) { |
|
1527 |
if (rexp.isVector()) { |
|
1528 |
return rexp.asDouble(); |
|
1529 |
} |
|
1530 |
else { |
|
1531 |
return Arrays.toString(rexp.asDoubles()); |
|
1532 |
} |
|
1533 |
} |
|
1534 |
else if (rexp instanceof org.rosuda.REngine.REXPInteger) { |
|
1535 |
if (rexp.isVector()) { |
|
1536 |
return rexp.asInteger(); |
|
1537 |
} |
|
1538 |
else { |
|
1539 |
return Arrays.toString(rexp.asIntegers()); |
|
1540 |
} |
|
1541 |
} |
|
1542 |
else if (rexp instanceof org.rosuda.REngine.REXPNull) { |
|
1543 |
return "NULL"; |
|
1544 |
} |
|
1545 |
} |
|
1546 |
catch (REXPMismatchException e) { |
|
1547 |
e.printStackTrace(); |
|
1548 |
} |
|
1549 |
return rexp; |
|
1550 |
} |
|
1551 |
|
|
1552 |
|
|
1553 |
/** |
|
1512 | 1554 |
* Safe eval. |
1513 | 1555 |
* |
1514 | 1556 |
* @param expr the expr |
... | ... | |
1532 | 1574 |
REXP r = null; |
1533 | 1575 |
try { |
1534 | 1576 |
r = connection.eval(expr); |
1577 |
|
|
1578 |
Log.info(" return: " + this.getCastedREXP(r)); //$NON-NLS-1$ |
|
1579 |
|
|
1535 | 1580 |
} |
1536 | 1581 |
catch (Exception e) { |
1537 | 1582 |
// TODO Auto-generated catch block |
... | ... | |
1547 | 1592 |
|
1548 | 1593 |
|
1549 | 1594 |
/** |
1550 |
* Checks if the eval command lines preference is set |
|
1551 |
* @return |
|
1552 |
*/ |
|
1553 |
public static boolean isLoggingEvalCommandLines() { |
|
1554 |
return RPreferences.getInstance().getBoolean(RPreferences.SHOW_EVAL_LOGS); |
|
1555 |
} |
|
1556 |
|
|
1557 |
/** |
|
1558 |
* Checks if the debug mode preference is set. |
|
1559 |
* @return |
|
1560 |
*/ |
|
1561 |
public static boolean isDebugMode() { |
|
1562 |
return RPreferences.getInstance().getBoolean(RPreferences.DEBUG); |
|
1563 |
} |
|
1564 |
|
|
1565 |
/** |
|
1566 |
* Sets the log. |
|
1567 |
* |
|
1568 |
* @param start the new log |
|
1569 |
*/ |
|
1570 |
public void setLog(boolean start) |
|
1571 |
{ |
|
1572 |
logging = start; |
|
1573 |
if (errorLogger != null) |
|
1574 |
this.errorLogger.setPrint(start); |
|
1575 |
if (inputLogger != null) |
|
1576 |
this.inputLogger.setPrint(start); |
|
1577 |
} |
|
1578 |
|
|
1579 |
/** |
|
1580 |
* Start logger. |
|
1581 |
* |
|
1582 |
* @param streamHog the stream hog |
|
1583 |
* @param streamHog2 the stream hog2 |
|
1584 |
* @return the r workspace |
|
1585 |
*/ |
|
1586 |
public RWorkspace stopLogger() { |
|
1587 |
this.errorLogger.stopLogging(); |
|
1588 |
this.inputLogger.stopLogging(); |
|
1589 |
return null; |
|
1590 |
} |
|
1591 |
|
|
1592 |
/** |
|
1593 |
* To txt. |
|
1594 |
* |
|
1595 |
* @param file the file |
|
1596 |
* @param symbol the symbol |
|
1597 |
* @throws StatException the stat exception |
|
1598 |
*/ |
|
1599 |
public void toTxt(File file, String symbol) throws StatException { |
|
1600 |
eval("write.table(" + symbol + file.getAbsolutePath().replace("\\", "\\\\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
1601 |
} |
|
1602 |
|
|
1603 |
/** |
|
1604 | 1595 |
* Bar delegate call to {@link Connection#voidEval(String)}. |
1605 | 1596 |
* |
1606 | 1597 |
* It is up to the caller to check if everything goes well (testing if the |
... | ... | |
1690 | 1681 |
|
1691 | 1682 |
|
1692 | 1683 |
/** |
1684 |
* Checks if the eval command lines preference is set |
|
1685 |
* @return |
|
1686 |
*/ |
|
1687 |
public static boolean isLoggingEvalCommandLines() { |
|
1688 |
return RPreferences.getInstance().getBoolean(RPreferences.SHOW_EVAL_LOGS); |
|
1689 |
} |
|
1690 |
|
|
1691 |
/** |
|
1692 |
* Checks if the debug mode preference is set. |
|
1693 |
* @return |
|
1694 |
*/ |
|
1695 |
public static boolean isDebugMode() { |
|
1696 |
return RPreferences.getInstance().getBoolean(RPreferences.DEBUG); |
|
1697 |
} |
|
1698 |
|
|
1699 |
/** |
|
1700 |
* Sets the log. |
|
1701 |
* |
|
1702 |
* @param start the new log |
|
1703 |
*/ |
|
1704 |
public void setLog(boolean start) |
|
1705 |
{ |
|
1706 |
logging = start; |
|
1707 |
if (errorLogger != null) |
|
1708 |
this.errorLogger.setPrint(start); |
|
1709 |
if (inputLogger != null) |
|
1710 |
this.inputLogger.setPrint(start); |
|
1711 |
} |
|
1712 |
|
|
1713 |
/** |
|
1714 |
* Start logger. |
|
1715 |
* |
|
1716 |
* @param streamHog the stream hog |
|
1717 |
* @param streamHog2 the stream hog2 |
|
1718 |
* @return the r workspace |
|
1719 |
*/ |
|
1720 |
public RWorkspace stopLogger() { |
|
1721 |
this.errorLogger.stopLogging(); |
|
1722 |
this.inputLogger.stopLogging(); |
|
1723 |
return null; |
|
1724 |
} |
|
1725 |
|
|
1726 |
/** |
|
1727 |
* To txt. |
|
1728 |
* |
|
1729 |
* @param file the file |
|
1730 |
* @param symbol the symbol |
|
1731 |
* @throws StatException the stat exception |
|
1732 |
*/ |
|
1733 |
public void toTxt(File file, String symbol) throws StatException { |
|
1734 |
eval("write.table(" + symbol + file.getAbsolutePath().replace("\\", "\\\\")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
1735 |
} |
|
1736 |
|
|
1737 |
|
|
1738 |
|
|
1739 |
/** |
|
1693 | 1740 |
* Loads a package library from its name. |
1694 | 1741 |
* @param p |
1695 | 1742 |
* @throws RWorkspaceException |
Formats disponibles : Unified diff