简体   繁体   English

如何在R中使用带有变量的函数?

[英]How to use function with variable in R?

in R,the pdf function can save graph in c:/test : 在R中,pdf函数可以将图形保存在c:/test

pdf("c:/test")

I want to make a variable substitue pdf ,how can i make it run ? 我想制作一个替代pdf的变量,我如何使其运行?

str<-"pdf"
str("c:/test")

get()这样做:

get(str)("c:/test")

s = "pdf" ; do.call(s, list("c:/test"))

or in two steps, 或分两步走

cl <- call(s, "c:/test")
eval(cl)

You can extract the function specified by the name in str with match.fun : 您可以使用match.fun提取str由名称指定的函数:

match.fun(str)("c:/test")

By the way: It is not a good idea to name an object str since this is the name of a basic function in R. 顺便说一句:命名对象str并不是一个好主意,因为这是R中基本功能的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM