如何将控制台输出存储到R中的变量

时间:2022-09-03 14:04:57

In R I would like to store a console command to a variable. I have already tried with the solutions proposed in the following link but without luck: In R, is it possible to redirect console output to a variable? Here you are the command I'm using:

在R中我想将控制台命令存储到变量中。我已经尝试过以下链接中提出的解决方案,但没有运气:在R中,是否可以将控制台输出重定向到变量?这是你正在使用的命令:

test <- capture.output(system("pa11y scuolafalconeborsellino.it; 
        perl -e \"print unpack('c', pack('C', $?)), \\$/\""), file = NULL)

The output visiblein the console is:

控制台中可见的输出是:

[4m[36m Welcome to Pa11y[39m[24m [90mWe'll sniff your page for you now. [39m [36m > [39mLoading page... [36m > [39mRunning HTML CodeSniffer... [36m > [39m[31mError: HTML CodeSniffer error[39m

[4m [36m欢迎来到Pa11y [39m [24m [90m]我们现在为您嗅探您的页面。 [39m [36m] [39mL加载页面... [36m> [39m运行HTML CodeSniffer ... [36m> [39m [31mError:HTML CodeSniffer error [39m]

-1

but the variable test is empty.

但是变量测试是空的。

Thank you!

1 个解决方案

#1


system has a parameter intern which can be used to save the output to a character vector:

system有一个参数实习生,可用于将输出保存到字符向量:

test <- system("pa11y scuolafalconeborsellino.it; perl -e \"print unpack('c', pack('C', $?)), \\$/\"", 
               intern = TRUE)

Note that system2 is now prefered and system should be avoided in new code.

请注意,系统2现在是首选,并且应该在新代码中避免使用系统。

#1


system has a parameter intern which can be used to save the output to a character vector:

system有一个参数实习生,可用于将输出保存到字符向量:

test <- system("pa11y scuolafalconeborsellino.it; perl -e \"print unpack('c', pack('C', $?)), \\$/\"", 
               intern = TRUE)

Note that system2 is now prefered and system should be avoided in new code.

请注意,系统2现在是首选,并且应该在新代码中避免使用系统。