Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R调用多个函数的优雅方式_R_Performance_Function_Dataframe - Fatal编程技术网

使用R调用多个函数的优雅方式

使用R调用多个函数的优雅方式,r,performance,function,dataframe,R,Performance,Function,Dataframe,我有一组预处理函数,我最终调用这些函数来创建最终的数据帧。正如您所见,每个阶段的输出都作为输入传递给下一阶段 wrap_func = function(DF){ # Wrapper function which has all the above functions put together. T1 = transform_ids(DF) print("Id transform

我有一组预处理函数,我最终调用这些函数来创建最终的数据帧。正如您所见,每个阶段的输出都作为输入传递给下一阶段

wrap_func = function(DF){  # Wrapper function which has all the above functions put together. 
T1 = transform_ids(DF)                                                          
print("Id transformation success")   #print statements are used for debugging purposes
T2 = transform_dates(T1)
print("date transformation success")
T3 = measurement_ids(T2)
print("measurement_ids transformation success")
T4 = oper_val_concepts(T3)
print("operator transformation success")
T5 = range_values(T4)
print("range capture success")
T6 = col_format(T5)
print("column formatting success")
T7 = missing_impute(T6,def_val)
print("Missing value Imputation success")
T7 = T7[c(                                                     # reordering the column display
"measurement_id","person_id")]
 return(T7)
 } 

DF = wrap_func(dfm)
有什么优雅的方式来写这个吗

这篇文章有类似的场景,但它是用Python编写的

你能帮我用R使这个变得优雅吗?

一个解决方案是:

管道% 转换ID%T>% catId转换成功\n%>% 转换日期%T>% catdate转换成功\n%>% 测量ID%T>% catmeasurement\u ids转换成功\n%>% 操作值概念%T>% catoperator转换成功\n%>% 范围\u值%T>% catrange捕获成功\n%>% 列格式%T>% catcolumn格式化成功\n%>% 缺少\u imputedef\u值%T>% catMissing值插补成功\n%>% [C测量id,人员id] } DF%允许您返回左侧值,因为您不想将打印的字符串通过管道传输到下一步

圆点。在末尾引用管道对象的数据帧

如果您喜欢使用print而不是cat,请确保将其放在大括号{printHello World!}之间

如果您愿意放弃调试消息或将其集成到每个独特的函数中,则可以使用purrr的compose:


管道您熟悉magrittr的管道%>%和dplyr之类的包吗?这种工作流在R中非常常见。感谢您的回复。我在我的单个函数中使用了%>%运算符来对数据帧执行操作。我对R不熟悉,所以不知道如何在这个场景中使用它来调用它们。%%>%基本上完全符合您的要求,请参见“确定”。谢谢,我会调查的,谢谢。我会努力的。向上投票。但这一条和老一条一样长。谢谢你的帮助。Will tryYou可能会使用更简洁的解决方案,但这将以放弃打印字符串为代价。例如,您可以使用purrr的compose创建一个独特的函数。我对没有打印语句很满意。我用compose编辑了我的答案,这使它成为一行!所以,从右到左创作作品。在上面的问题中,transform_id是必须执行的第一个函数?