Learn R Programming

chatAI4R (version 1.3.1)

interpretResult: Interpret Analysis Results

Description

This function constructs an interpretation prompt based on the analysis type and passes it to the `chat4R` function.

Usage

interpretResult(
  analysis_type,
  result_text,
  custom_template = NULL,
  model = "gpt-5-nano",
  temperature = 1,
  api_key = Sys.getenv("OPENAI_API_KEY"),
  use_fallback = TRUE,
  fallback_model = "gpt-5-nano"
)

Value

The interpretation produced by AI (data.frame with a `content` column by default)

Arguments

analysis_type

A character string indicating the type of analysis. Valid values include "summary", "PCA", "regression", "group_comparison", "visualization", "time_series", "clustering", "biological_implication", "statistical_metrics", "test_validity", "report", "preprocessing", and "custom".

result_text

An object containing the analysis result to be interpreted. If it is not a character string, it will be converted to one using capture.output.

custom_template

An optional custom prompt template to be used when analysis_type is "custom". If NULL, a default prompt is used.

model

The chat model to use (default: "gpt-5-nano"). Set to another supported model string if needed.

temperature

Sampling temperature passed to the chat model (default: 1).

api_key

API key passed to `chat4R` (defaults to OPENAI_API_KEY).

use_fallback

If TRUE, falls back to `fallback_model` when the primary model errors.

fallback_model

Model used when the primary model errors (default: "gpt-5-nano"). Ignored if `use_fallback = FALSE` or the primary succeeds.

Author

Satoshi Kume

Examples

Run this code
if (FALSE) {
# Example: interpret PCA results of the iris dataset
pca_res <- prcomp(iris[, 1:4], scale. = TRUE)
interpretation <- interpretResult("PCA", summary(pca_res))
cat(interpretation$content)
}

Run the code above in your browser using DataLab