To accomplish R integration with Minitab Statistical Software, Minitab, LLC provides the mtbr package. The following descriptions of the functions from the mtbr package prepare you to write R code that integrates with Minitab.

For information on how to install Minitab's R package and how to run R from Minitab, go to Installing R to use with Minitab Statistical Software.

For more information on R, consult the guidance available at www.r-project.org.

Package: mtbr

mtb_get_column

Retrieves a column from a Minitab worksheet to use in R.

name: character
Specifies the column to retrieve. You can specify either the column number (for example, "C1") or the column name (for example, "My Column").
Return value
Returns the column of data from the active worksheet as an R atomic vector. The atomic vector can contain character or numeric values.
Example
library(mtbr)

column1 <- mtb_get_column("C1")
column2 <- mtb_get_column("My Column")

mtb_get_constant

Retrieves a constant from a Minitab worksheet to use in R.

name: character
Specifies the constant to retrieve. You can specify either the constant number (for example, "K1") or the constant name (for example, "My Constant").
Return value
Returns a constant that can be a character or numeric value.
Example
library(mtbr)

constant1 <- mtb_get_constant("K1")
constant2 <- mtb_get_constant("My Constant")

mtb_get_matrix

Retrieves a matrix from a Minitab worksheet to use in R.

name: character
Specifies the matrix to retrieve. You can specify either the matrix number (for example, "M1") or the matrix name (for example, "My Matrix").
Return value
Returns the data from the matrix as an R matrix.
Example
library(mtbr)

matrix1 <- mtb_get_matrix("M1")
matrix2 <- mtb_get_matrix("My Matrix")

mtb_add_message

Appends a message to the Minitab Output pane.

message: character
Specifies the message to display.
Return value
Null
Example
library(mtbr)

mtb_add_message("This is a message.")

mtb_set_note

Sets a note at the top of the Minitab Output pane.

note: character
Specifies the text to display.
Return value
Null
Example
library(mtbr)

mtb_set_note("The output contains one note.")

mtb_set_title

Sets the title at the top of the Minitab Output pane.

title: character
Specifies the text to display.
Return value
Null
Example
library(mtbr)

mtb_set_title("The output contains one title.")

mtb_add_image

Appends an image to the Minitab Output pane when you have a supported image file.

filename: character
Specifies the path to the image.
Return value
Null
Example
library(mtbr)

png("histogram.png")
hist(airquality$Temp)
dev.off() 
mtb_add_image("histogram.png")

mtb_add_image_bytes

Appends an image to the Minitab Output pane when you have a bytes object.

image_bytes: raw vector
Specifies the bytes of data for an image. For example, you can enter a raw vector as the parameter.
Return value
Null
Example
library(mtbr)

image_data <- as.raw(c(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a,
                       0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48,
                       0x44, 0x52, 0x00, 0x00, 0x00, 0x09, 0x00,
                       0x00, 0x00, 0x09, 0x08, 0x02, 0x00, 0x00,
                       0x00, 0x6f, 0xf3, 0x91, 0x47, 0x00, 0x00,
                       0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00,
                       0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x00,
                       0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00,
                       0xb1, 0x8f, 0x0b, 0xfc, 0x61, 0x05, 0x00,
                       0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73,
                       0x00, 0x00, 0x16, 0x25, 0x00, 0x00, 0x16,
                       0x25, 0x01, 0x49, 0x52, 0x24, 0xf0, 0x00,
                       0x00, 0x00, 0x22, 0x49, 0x44, 0x41, 0x54,
                       0x18, 0x57, 0x63, 0xd8, 0x61, 0xbb, 0x8b,
                       0x81, 0x01, 0x27, 0x49, 0xba, 0x04, 0x01,
                       0x69, 0x9c, 0x12, 0x04, 0xa4, 0x71, 0x4a,
                       0x10, 0x90, 0xc6, 0x29, 0xb1, 0xc3, 0x76,
                       0x17, 0x00, 0xfc, 0x0b, 0x45, 0x08, 0x6f,
                       0x2c, 0xff, 0xe2, 0x00, 0x00, 0x00, 0x00,
                       0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
                       0x82))
mtb_add_image_bytes(image_data)

mtb_add_table

Appends a table to the Minitab Output pane.

columns: data.frame or list of atomic vectors
Specifies the columns of data for the table as a list of atomic vectors or as a data.frame.
headers: character vector (Optional)
Specifies the column headers for the table. The default headers is an empty character vector.
title: character (Optional)
Specifies the title for the table. The default title is "".
footnote: character (Optional)
Specifies the footnote under the table. The default footnote is "".
Return value
Null
Example
library(mtbr)

mytitle <- "Air Quality Data"
myheaders <- names(airquality)
mycolumns <- airquality
myfootnote <- gsub("\"", "", paste0(capture.output(summary(airquality)[4,]), collapse = "\n"))
mtb_add_table(columns=mycolumns, headers=myheaders, title=mytitle, footnote=myfootnote)

Converting from a Minitab date format to an R date format

By default, Minitab uses a different datetime format than R. To convert from the Minitab datetime format to the Unix datetime format, use the excel_numeric_to_date() function from the janitor R package.

Errors from combined character sets on Microsoft® Windows

R on Microsoft® Windows cannot always process strings that have characters from different character sets. For example, if Microsoft® Windows uses the Japanese (Shift-JIS) character set and a string includes characters from the Chinese (GBK) character set, some strings will not be processed correctly.

Because of this limitation, one possible solution is that strings use characters from the same character set as the Microsoft® Windows display language.