Skip to contents

The studio guide for mascot_read_character(). The same page is read in the mascot studio.

Try it live. The mascot studio shows this function with live controls and the generated code. In an R session with the optional packages bslib and knitr installed, run:
mascot::mascot_studio(fn = "mascot_read_character")
It opens on this function's guide; change a control and watch the mascot.
Experimental Its arguments, results and diagnostics may change in a later release. What the file format accepts may grow; version-1 files keep loading.

Read a character file

mascot_read_character() reads a JSON character file from a path, checks it, and returns a checked character. Pass the result to the character argument of mascot() or mascot_preview(). The package ships one example file, so the call below runs offline:

path <- system.file("examples", "characters", "study_bot.json", package = "mascot")
bot <- mascot::mascot_read_character(path)
mascot::mascot_preview(character = bot)

What R prints for that character:

study_bot: Study Bot (visorfolk)
Moods: idle, thinking, happy, worried, celebrating
Gestures: rock, nod, wave, greet
Detail overrides: micro
From: .../examples/characters/study_bot.json

Limits

The studio and mascot_studio(character =) take the built-in characters only. A file that cannot be read, or that fails the check, gives an error that names the problem; mascot_check_character() checks a plain list the same way.

Warnings, errors and common mistakes

mascot_read_character("no-such-file.json")
Error: could not find function "mascot_read_character"