Skip to contents

A parse failure (code_parse_r(), via code_check's parse_error) is usually a genuine defect in the paper's code — but occasionally the file was never R source at all (a serialized JSON/HTML widget export saved with a .R extension) or is a well-known non-R DSL (a JAGS/BUGS model definition, see .repro_is_jags_model()). Reporting either of those as "failed to parse" reads identically to a real syntax error in real analysis code, giving a reader no way to tell "the author has a bug" from "this file was never R to begin with".

Usage

.repro_content_sniff(code_text)

Arguments

code_text

the file's raw text (character vector, one element per line, as read by code_read()/code_extract_r())

Value

NA_character_ when nothing matches (treat as a genuine parse failure), else one of "JSON", "HTML", "XML" naming what was detected

Details

Deliberately conservative: only the UNAMBIGUOUS cases are flagged (a JSON object/array spanning essentially the whole file, or a clear HTML/XML doctype/tag at the very start) — checked on the RAW text, not something code_parse_r() already tried to parse as R, so this never depends on why the parse failed. Anything else (including a real, if unusual, R script) is left alone and reported as a genuine parse failure, same as before this existed.