本文整理汇总了Python中RUtil.run方法的典型用法代码示例。如果您正苦于以下问题:Python RUtil.run方法的具体用法?Python RUtil.run怎么用?Python RUtil.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RUtil
的用法示例。
在下文中一共展示了RUtil.run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: import RUtil [as 别名]
# 或者: from RUtil import run [as 别名]
def process(args, table_lines):
"""
@param args: command line or web input
@param table_lines: input lines
@return: the image data as a string
"""
rtable = RUtil.RTable(table_lines)
header_row = rtable.headers
data_rows = rtable.data
Carbone.validate_headers(header_row)
# Read the relevant columns and their labels.
plot_info = PlotInfo(args, header_row, data_rows)
# Get info for the temporary data
augmented_lines = plot_info.get_augmented_table_lines()
# Create a temporary data table file for R.
table_string = "\n".join(augmented_lines)
temp_table_name = Util.create_tmp_file(table_string, suffix=".table")
# Create a temporary pathname for the plot created by R.
temp_plot_name = Util.get_tmp_filename()
# Create a temporary R script file.
script = plot_info.get_script(args, temp_plot_name, temp_table_name)
temp_script_name = Util.create_tmp_file(script, suffix=".R")
# Call R.
retcode, r_out, r_err = RUtil.run(temp_script_name)
if retcode:
raise ValueError("R error:\n" + r_err)
# Delete the temporary data table file.
os.unlink(temp_table_name)
# Delete the temporary script file.
os.unlink(temp_script_name)
# Read the image file.
try:
with open(temp_plot_name, "rb") as fin:
image_data = fin.read()
except IOError as e:
raise HandlingError("the R call seems to not have created the plot")
# Delete the temporary image file.
os.unlink(temp_plot_name)
# Return the image data as a string.
return image_data