Title: | Check 'C' and 'C++' Files using 'Cppcheck' |
---|---|
Description: | Allow to run 'Cppcheck' (<https://cppcheck.sourceforge.io/>) on 'C' and 'C++' files with a 'R' command or a 'RStudio' addin. The report appears in the 'RStudio' viewer pane as a formatted 'HTML' file. It is also possible to get this report with a 'shiny' application. 'Cppcheck' can spot many error types and it can also give some recommendations on the code. |
Authors: | Stéphane Laurent [aut, cre], Amit Gupta [cph] ('fast-xml-parser' library), luyilin [cph] ('json-format-highlight' library) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-10-24 03:13:09 UTC |
Source: | https://github.com/stla/cppcheckr |
HTML widget which runs Cppcheck.
cppcheckR( path, std = NULL, def = NULL, undef = NULL, checkConfig = FALSE, height = NULL, elementId = NULL )
cppcheckR( path, std = NULL, def = NULL, undef = NULL, checkConfig = FALSE, height = NULL, elementId = NULL )
path |
path to a C/C++ file or to a folder containing C/C++ files |
std |
the standard, one of |
def |
character vector of symbols you want to define, e.g.
|
undef |
character vector of symbols you want to undefine;
if |
checkConfig |
Boolean, whether to run Cppcheck with the
option |
height |
height in pixels (defaults to automatic sizing) |
elementId |
an id for the widget, this is usually useless |
A htmlwidget
object.
example <- function(file){ filepath <- system.file("cppexamples", file, package = "cppcheckR") lines <- readLines(filepath) print(cppcheckR(filepath, std = "c++03", def = NA, undef = NA)) message(file, ":") cat(paste0(format(seq_along(lines)), ". ", lines), sep = "\n") } example("memleak.cpp") example("outofbounds.cpp") example("unusedvar.cpp") example("useless.cpp")
example <- function(file){ filepath <- system.file("cppexamples", file, package = "cppcheckR") lines <- readLines(filepath) print(cppcheckR(filepath, std = "c++03", def = NA, undef = NA)) message(file, ":") cat(paste0(format(seq_along(lines)), ". ", lines), sep = "\n") } example("memleak.cpp") example("outofbounds.cpp") example("unusedvar.cpp") example("useless.cpp")
cppcheckR
Output and render functions for using cppcheckR
within
Shiny applications and interactive Rmd documents.
cppcheckROutput(outputId, width = "100%", height = "400px") renderCppcheckR(expr, env = parent.frame(), quoted = FALSE)
cppcheckROutput(outputId, width = "100%", height = "400px") renderCppcheckR(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
a valid CSS unit (like |
expr |
an expression that generates a ' |
env |
the environment in which to evaluate |
quoted |
logical, whether |
cppcheckROutput
returns an output element that can be
included in a Shiny UI definition, and renderCppcheckRR
returns a
shiny.render.function
object that can be included in a Shiny server
definition.
Render a formatted JSON string in HTML.
json2html( json, outfile = NULL, pandoc = FALSE, style = paste0("background-color: #051C55; color: #E76900; ", "font-size: 15px; font-weight: bold; margin: 0; ", "white-space: pre-wrap; outline: #051C55 solid 10px;"), keyColor = "crimson", numberColor = "chartreuse", stringColor = "lightcoral", trueColor = "#00cc00", falseColor = "#ff8080", nullColor = "cornflowerblue" )
json2html( json, outfile = NULL, pandoc = FALSE, style = paste0("background-color: #051C55; color: #E76900; ", "font-size: 15px; font-weight: bold; margin: 0; ", "white-space: pre-wrap; outline: #051C55 solid 10px;"), keyColor = "crimson", numberColor = "chartreuse", stringColor = "lightcoral", trueColor = "#00cc00", falseColor = "#ff8080", nullColor = "cornflowerblue" )
json |
a JSON string or a path to a JSON file |
outfile |
either a path to a html file, or |
pandoc |
Boolean, whether to use pandoc |
style |
some CSS for the container, only if |
keyColor |
color of the keys, only if |
numberColor |
color of the numbers, only if |
stringColor |
color of the strings, only if |
trueColor |
color of the |
falseColor |
color of the |
nullColor |
color of the |
Nothing if outfile
is not NULL
, otherwise the HtML
as a character string.
library(cppcheckR) xml <- system.file("extdata", "order-schema.xml", package = "xml2") json <- xml2json(xml) html <- json2html(json) library(htmltools) if(interactive()){ browsable(HTML(html)) } # with pandoc html <- json2html(json, pandoc = TRUE) if(interactive()){ browsable(HTML(html)) }
library(cppcheckR) xml <- system.file("extdata", "order-schema.xml", package = "xml2") json <- xml2json(xml) html <- json2html(json) library(htmltools) if(interactive()){ browsable(HTML(html)) } # with pandoc html <- json2html(json, pandoc = TRUE) if(interactive()){ browsable(HTML(html)) }
Run a shiny application to check C/C++ files.
shinyCppcheck()
shinyCppcheck()
Nothing, this just launches a Shiny app.
The packages listed in the Suggests field of the package description are required.
Convert XML to a JSON string.
xml2json( xml, spaces = 2L, linebreaks = FALSE, replacer = NULL, attributeNamePrefix = "@_", textNodeName = "#text", ignoreAttributes = FALSE, ignoreNameSpace = FALSE, parseNodeValue = TRUE, parseAttributeValue = TRUE, trimValues = TRUE )
xml2json( xml, spaces = 2L, linebreaks = FALSE, replacer = NULL, attributeNamePrefix = "@_", textNodeName = "#text", ignoreAttributes = FALSE, ignoreNameSpace = FALSE, parseNodeValue = TRUE, parseAttributeValue = TRUE, trimValues = TRUE )
xml |
either a XML file or some XML given as a character string |
spaces |
an integer, the indentation |
linebreaks |
Boolean, whether to break the lines in the JSON string when there are some linebreaks; this generates an invalid JSON string |
replacer |
character vector, the body of the second argument of
|
attributeNamePrefix |
prefix for the attributes |
textNodeName |
name of text nodes, which appear for nodes which have both a text content and some attributes |
ignoreAttributes |
Boolean, whether to ignore the attributes |
ignoreNameSpace |
Boolean, whether to ignore the namespaces |
parseNodeValue |
Boolean, whether to parse the node values to numbers if possible |
parseAttributeValue |
Boolean, whether to parse the attribute values to numbers if possible |
trimValues |
Boolean, whether to trim the values |
A JSON string.
xml <- system.file("extdata", "order-schema.xml", package = "xml2") cat(xml2json(xml)) # js <- c( 'if(key === "@_type"){', ' return undefined;', '} else if(key === "@_name"){', ' return value.toUpperCase();', '}', 'return value;' ) cat(xml2json(xml, linebreaks = TRUE, replacer = js))
xml <- system.file("extdata", "order-schema.xml", package = "xml2") cat(xml2json(xml)) # js <- c( 'if(key === "@_type"){', ' return undefined;', '} else if(key === "@_name"){', ' return value.toUpperCase();', '}', 'return value;' ) cat(xml2json(xml, linebreaks = TRUE, replacer = js))