tests/testthat/test_print.R

## Tests for print function

library(ranger)
context("ranger_print")

## Initialize the random forest
rf <- ranger(Species ~ ., iris, num.trees = 5, write.forest = TRUE)

## Test print ranger function
expect_that(print(rf), prints_text("Ranger result"))

## Test print forest function
expect_that(print(rf$forest), prints_text("Ranger forest object"))

## Test print prediction function
expect_that(print(predict(rf, iris)), prints_text("Ranger prediction"))

## Test str ranger function
expect_that(str(rf), prints_text("List of 15"))

## Test str forest function
expect_that(str(rf$forest), prints_text("List of 9"))

Try the ranger package in your browser

Any scripts or data that you put into this service are public.

ranger documentation built on Nov. 13, 2023, 1:09 a.m.