The
RSCR command extends Minitab's functionality with
R but does not make Minitab an interactive
R environment. As such, use Minitab only with
R scripts that complete without interaction. For example, the
readline()
function, which accepts input from the keyboard while a script runs, does not work in Minitab. Interactivity in
R takes many other forms, such as
plot()
and
hist()
.
For more information on Minitab's R package, including R code examples, go to R API Reference.
All the files referenced in this guide are available in this .ZIP file: r_guide_files.zip.
Install and run R before you attempt to integrate R with Minitab Statistical Software. For assistance with the installation of R, please consult with your organization's technical support department. Minitab Technical Support cannot assist with the installation of R.
You can run the RSCR command in the Command Line pane. For general information about the Command Line pane, go to Command Line/History pane. For general information about using session commands, go to Session Command help.
Runs the R script that you specify.
The default file extension for R scripts is .R. If the file extension is .R, you do not need to type the file extension.
Minitab looks for R scripts in the default folder if you do not specify a file path. The default folder location depends on your operating system. For more information, go to Default folders for R files for Minitab.
The optional argument
Args allows you to pass arguments to the
R script through
commandArgs(trailingOnly = TRUE)
.
Args can be any text values separated by a space. Enclose arguments in quotation marks. The default value is
Null
, which indicates that the script does not receive any arguments.
In general, you use arguments to bring data from Minitab into R. You can enter arguments in several ways. For example, you can use arguments that are identifiers for columns, matrices, or constants.
Minitab Session Command | Value in R | Usage |
---|---|---|
|
|
Use the following function to retrieve the column:
|
|
|
Use the following function to retrieve the matrix:
|
|
|
Use the following function to retrieve the constant:
|
You can also use arguments that are the names of columns, matrices, or constants in Minitab.
Minitab Session Command | Value in R | Usage |
---|---|---|
|
|
Use the following function to retrieve the column:
|
|
|
Use the following function to retrieve the matrix:
|
|
|
Use the following function to retrieve the constant:
|
You can also specify arguments to pass text to use in your R code. You can pass text directly or in a constant.
Minitab Session Command | Value in R | Usage |
---|---|---|
|
|
This case passed a value that cannot be used with an
mtbr 'get ' command. However,
Args are not limited to only passing columns, matrices, and constants.
|
|
|
This case highlights that, although RSCR does not accept arguments that are not text values, you can pass a constant to RSCR as long as the constant is defined as a text value. |
When you pass more than one argument, you can access the arguments in order from the list of arguments.
Minitab Session Command | Value in R | Usage |
---|---|---|
|
|
This case is an example of passing multiple
Args, where you would access them by using the following functions in
R:
|
File | Description |
---|---|
test.R | A sample R script that is used throughout this guide. When you pass arguments to the script, the results include a list of the values of the arguments. When you run the script with the argument "ArgToBePrintedToStdErr", the script writes the name of the argument to the stderr file. When you run the script with the argument "ArgToBePrintedToStdOut", the script writes the name of the argument to the stdout file. Use the subcommands that follow to control whether the contents of these files appear in Minitab's Output pane. |
message()
,
warning()
, or
stop()
) console output in the Output pane in Minitab. The warning console output is where
R error messages display when you run your code in an
R integrated development environment. However, you can use
R to save other results in the warning file. For example, by default:
RSCR "test.R" "ArgToBePrintedToStdErr".
Produces the following results that include the warning console output: RSCR "test.R" "ArgToBePrintedToStdErr";
NOSERR.
The session commands produce the following results: print()
) in the Output pane in Minitab. The standard console output is where the results of commands like
print()
display in an
R integrated development environment. For example, by default:
RSCR "test.R" "ArgToBePrintedToStdOut".
Produces the following results that exclude the console output: RSCR "test.R" "ArgToBePrintedToStdOut";
SOUT.
The session commands produce the following results: File | Description |
---|---|
test.R | A sample R script that is used throughout this guide. When you pass arguments to the script, the results include a list of the values of the arguments. |
REXEC.MTB | A sample Minitab exec file that includes the session commands to run the test.R script with 2 arguments. |
Execs are text files that contain Minitab session commands. The RSCR command runs R in a Minitab exec. With exec files, you can easily run commands without re-typing them, and you can assign the exec to a custom button in Minitab. For more information about Minitab execs, go to Minitab Macros Help. To run an exec, choose .
RSCR "test.R" "Arg1" "Arg2"
To run the
R script with the exec, use the following steps:
If you have a Minitab exec file, you can create a custom button or menu that runs the exec. For general information on how to customize the interface in Minitab, go to Customize menus, toolbars and shortcut keys.
In addition to customizing Minitab's interface, you can use a COM-compliant language to create custom dialog boxes and analyses. For information on how to customize Minitab through COM, go to Minitab Automation.
Press Ctrl + Alt + Delete to open the Microsoft® Windows Task Manager. Then, end the R process.