content
stringlengths
0
14.9M
filename
stringlengths
44
136
matchFunctionSignature <- function(aFunction_f_1, aFunctionTemplate_f_1 = function(){}) { if (!is.function(aFunction_f_1)) return(FALSE) identical( retrieveFunctionArguments(aFunctionTemplate_f_1), retrieveFunctionArguments(aFunction_f_1) ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/matchFunctionSignature.R
opInformation <- function() { stratum <- buildIdentityList(c('core', paste0('layer_', 1:3))) phasing <- buildIdentityList(c('design', 'build', 'test', 'run', 'maintain', 'evolve', 'transversal')) intent <- buildIdentityList(c('parts_building', 'parts_assembly', 'quality_control', 'statistics', 'feedback', 'content_generation', 'utilities')) category <- buildIdentityList(c('function', 'class', 'data')) nature <- buildIdentityList(c('exported', 'internal')) buildList <- function(name_s_1, category_s_1, nature_s_1, stratum_s_1, phasing_s_1, intent_s_1) { list(name = name_s_1, category = category_s_1, nature = nature_s_1, stratum = stratum_s_1, phasing = phasing_s_1, intent = intent_s_1 ) } bec <- function(name_s_1, stratum_s_1, phasing_s_1, intent_s_1) { buildList(name_s_1, category$CLASS, nature$EXPORTED, stratum_s_1, phasing_s_1, intent_s_1) } bef <- function(name_s_1, stratum_s_1, phasing_s_1, intent_s_1) { buildList(name_s_1, category$FUNCTION, nature$EXPORTED, stratum_s_1, phasing_s_1, intent_s_1) } bif <- function(name_s_1, stratum_s_1, phasing_s_1, intent_s_1) { buildList(name_s_1, category$FUNCTION, nature$INTERNAL, stratum_s_1, phasing_s_1, intent_s_1) } dt <- data.table::rbindlist(list( bef('defineEvaluationModes', stratum$LAYER_3, phasing$BUILD, intent$PARTS_BUILDING), bef('defineFunctionReturnTypesParameterName', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bef('defineTestCaseDefinitionsParameterName', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bec('EvaluationMode', stratum$CORE, phasing$RUN, intent$PARTS_BUILDING), bec('FunctionParameterTypeFactory', stratum$CORE, phasing$RUN, intent$PARTS_BUILDING), bec('FunctionParameterName', stratum$CORE, phasing$RUN, intent$PARTS_BUILDING), bec('TestCaseDefinition', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bef('verifyClassName', stratum$LAYER_1, phasing$BUILD, intent$QUALITY_CONTROL), bef('verifyFunctionName', stratum$LAYER_1, phasing$BUILD, intent$QUALITY_CONTROL), bef('verifyObjectNames', stratum$LAYER_1, phasing$RUN, intent$UTILITIES), bef('verifyFunctionReturnTypesDefinition', stratum$LAYER_1, phasing$RUN, intent$QUALITY_CONTROL), bef('verifyTestCaseDefinitions', stratum$LAYER_1, phasing$RUN, intent$QUALITY_CONTROL), bef('retrieveFunctionReturnTypes', stratum$LAYER_1, phasing$RUN, intent$UTILITIES), bef('retrieveTestCaseDefinitions', stratum$LAYER_1, phasing$RUN, intent$UTILITIES), bef('runFunction', stratum$LAYER_1, phasing$RUN, intent$UTILITIES), bef('isAuditable', stratum$CORE, phasing$RUN, intent$UTILITIES), bef('opInformation', stratum$LAYER_3, phasing$RUN, intent$FEEDBACK), bef('identifyOPInstrumentationLevel', stratum$LAYER_3, phasing$RUN, intent$FEEDBACK), bef('exploreObjectNamesVerification', stratum$LAYER_3, phasing$RUN, intent$FEEDBACK), bef('findFilesInPackage', stratum$LAYER_3, phasing$RUN, intent$UTILITIES), bif('generateStatusSummary', stratum$LAYER_3, phasing$RUN, intent$UTILITIES), bif('getClassTypicalFunctionNames', stratum$LAYER_2, phasing$BUILD, intent$PARTS_ASSEMBLY), bef('getEllipsisName', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bef('getObjectClassKind', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bef('getObjectClassNames', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bef('getObjectFunctionArgumentNames', stratum$CORE, phasing$RUN, intent$PARTS_BUILDING), bef('getObjectFunctionNames', stratum$CORE, phasing$RUN, intent$PARTS_BUILDING), bif('hasMainClass', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bif('matchFunctionArguments', stratum$CORE, phasing$BUILD, intent$PARTS_BUILDING), bef('retrieveFactory', stratum$CORE, phasing$RUN, intent$PARTS_ASSEMBLY), bef('retrieveFunctionArguments', stratum$LAYER_1, phasing$BUILD, intent$PARTS_BUILDING), bef('retrieveFunctionArgumentNames', stratum$LAYER_1, phasing$BUILD, intent$PARTS_BUILDING), bef('retrievePackageFunctionNames', stratum$LAYER_3, phasing$RUN, intent$UTILITIES), bif('retrieveSupportedObjectInformation', stratum$LAYER_1, phasing$BUILD, intent$PARTS_BUILDING), bef('retrieveTestCaseDescriptions', stratum$LAYER_3, phasing$RUN, intent$PARTS_BUILDING), bef('runTestCase', stratum$LAYER_3, phasing$RUN, intent$PARTS_BUILDING), bef('runTransientFunction', stratum$LAYER_3, phasing$RUN, intent$PARTS_BUILDING), bif('verifyName', stratum$LAYER_1, phasing$RUN, intent$PARTS_BUILDING), bef('verifyFunctionArguments', stratum$LAYER_3, phasing$BUILD, intent$QUALITY_CONTROL), bef('matchFunctionSignature', stratum$LAYER_3, phasing$RUN, intent$PARTS_BUILDING) ) ) name <- NULL # nse dt[order(name)] }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/opInformation.R
abort <- function(msg_s_1, ...) { stop(paste(msg_s_1, ...)) } strJoin <- function(text_s, join_s_n = ', ') paste(text_s, sep = '', collapse = join_s_n) strBracket <- function(text_s_n) { paste0('[', text_s_n, ']') } destroySpaces <- function(text_s) { gsub('[\\s\\b]+', '', text_s, perl = TRUE) } removeFilenameExtension <- function(filename_s_1m) { b <- stringr::str_count(filename_s_1m, '\\.') special_files <- grepl('^\\.+$', filename_s_1m, perl = TRUE) rfe <- function(fn_s_1) { s <- strsplit(fn_s_1, '.', fixed = TRUE)[[1]] paste0(s[-length(s)], collapse = '.') } vrfe <- Vectorize(rfe) ifelse(b != 0 & !special_files, vrfe(filename_s_1m), filename_s_1m ) } guardExecution <- function(yourExpression_ex, instrumentWarnings_b = TRUE) { if (instrumentWarnings_b) { tryCatch(yourExpression_ex, error = function(e) e, warning = function(w) w) } else { tryCatch(yourExpression_ex, error = function(e) e) } } buildIdentityList <- function(entries_s) { d <- toupper(entries_s) names(d) <- gsub('[^A-Z0-9_]', '', d, perl = TRUE) as.list(d) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/outOfPackage.R
retrieveFactory <- function() { traceFactory <- function(factory_o_1, info_s_1 = 'default') { if (isAuditable()) { cat(info_s_1, 'type factory address', data.table::address(factory_o_1), '\nsuffixes', strBracket(strJoin(factory_o_1$retrieveKnownSuffixes())), "\n") } factory_o_1 } g <- options('op_type_factory')$op_type_factory if (is.environment(g) && is(g, 'FunctionParameterTypeFactory')) return(traceFactory(g, 'user defined')) traceFactory(FunctionParameterTypeFactory()) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveFactory.R
retrieveFunctionArgumentNames <- function(fun_f_1) { if (is.primitive(fun_f_1)) { a <- args(fun_f_1) if (is.null(a)) return('') formalArgs(a) } else formalArgs(fun_f_1) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveFunctionArgumentNames.R
retrieveFunctionArguments <- function(fun_f_1) { if (is.primitive(fun_f_1)) { a <- args(fun_f_1) if (is.null(a)) return(a) formals(a) } else formals(fun_f_1) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveFunctionArguments.R
retrieveFunctionReturnTypes <- function(object_o_1) { von <- verifyObjectNames(object_o_1) if (!von$can_be_typed_checked) return(von) v <- verifyFunctionReturnTypesDefinition(object_o_1, von$is_function_fully_instrumented) if (!v$validity) return(v) von$sof$instrumented_fn }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveFunctionReturnTypes.R
retrievePackageFunctionNames <- function(packageName_s_1, libraryPath_s_1 = .libPaths()[1]) { if (!packageName_s_1 %in% installed.packages()[, 'Package']) abort('package', strBracket(packageName_s_1), 'is not installed') sn <- packageName_s_1 if (!sn %in% search()) { tt <- paste0('package:', packageName_s_1) if (!tt %in% search()) library(packageName_s_1, character.only = TRUE) sn <- tt } if (sn %in% search()) { l <- ls(sn, all.names = TRUE) return(l[sapply(l, function(e) is.function(get(e)))]) } abort('package', strBracket(packageName_s_1), 'not found in search path') }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrievePackageFunctionNames.R
retrieveSupportedObjectInformation <- function(object_o_1) { if (!is.object(object_o_1)) abort('parameter named object_o_1 is not an object') v <- getObjectClassKind(object_o_1) supported <- c('environment', 'S3', 'R6', 'S4', 'RC') if (!v %in% supported) abort(paste('parameter object_o_1 is not of supported type', strBracket(v), 'supported types are', strBracket(strJoin(supported)))) dfrtpn <- defineFunctionReturnTypesParameterName() dtcdpn <- defineTestCaseDefinitionsParameterName() if (v != 'S4') { ll <- ls(object_o_1) return(list(frt = dfrtpn %in% ll, tcd = dtcdpn %in% ll, instrumented_fn = object_o_1[[dfrtpn]], instrumented_tc = object_o_1[[dtcdpn]] )) } f <- .hasSlot(object_o_1, dfrtpn) t <- .hasSlot(object_o_1, dtcdpn) list( frt = f, tcd = t, instrumented_fn = if (f) object_o_1@function_return_types else NA, instrumented_tc = if (t) object_o_1@test_case_definitions else NA ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveSupportedObjectInformation.R
retrieveTestCaseDefinitions <- function(object_o_1) { von <- verifyObjectNames(object_o_1) if (!von$owns_test_case_definitions) return(von) v <- verifyTestCaseDefinitions(object_o_1, von$is_test_case_fully_instrumented) if (!v$validity) return(v) von$sof$instrumented_tc }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveTestCaseDefinitions.R
retrieveTestCaseDescriptions <- function(object_o_1) { tcd <- retrieveTestCaseDefinitions(object_o_1) if (!is.data.table(tcd)) return('provided object owns no test case definitions') data.table(function_name = tcd$function_name, description = sapply(1:nrow(tcd), function(e) tcd[e]$test_case[[1]]$getDescription())) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/retrieveTestCaseDescriptions.R
runFunction <- function(object_o_1, functionName_s_1, arguments_l, evaluationMode_o_1) { cn <- getObjectClassNames(object_o_1)$classname fn <- guardExecution(get(functionName_s_1, envir = object_o_1)) if (!is.function(fn)) abort('unable to identify function', strBracket(functionName_s_1), 'from object of type', strBracket(cn)) if (!is.list(arguments_l)) abort('arguments_l must be a list, got', strBracket(typeof(arguments_l))) buildResult <- function(status_b_1, value_, mode_s_1, frt_l_1, pc_l_1) { list(status = status_b_1, value = value_, mode = mode_s_1, function_return_check = frt_l_1, parameter_check = pc_l_1) } rv <- guardExecution(do.call(fn, arguments_l)) modes <- defineEvaluationModes() if (evaluationMode_o_1$is(modes[1])) return(buildResult(TRUE, rv, modes[1], NA, NA)) frt <- retrieveFunctionReturnTypes(object_o_1) if (!functionName_s_1 %in% frt$function_name) abort('function', strBracket(functionName_s_1), 'is not instrumented in object of class', strBracket(cn)) function_name <- NULL # data.table NSE issue with Rcmd check tf <- retrieveFactory() b <- tf$verifyValue( FunctionParameterName(frt[function_name == functionName_s_1]$return_value), rv) s <- buildResult(b$validity, rv, modes[2], b$validity, NA) s$function_return_type_check <- rbindlist(list(b)) if (evaluationMode_o_1$is(modes[2])) return(s) fa <- getObjectFunctionArgumentNames(object_o_1) mfa <- matchFunctionArguments(arguments_l, fa[[functionName_s_1]]) pcv <- all(mfa$validity) r <- buildResult(pcv && b$validity, rv, modes[3], b$validity, pcv) r$parameter_type_checks <- mfa r$function_return_type_check <- s$function_return_type_check r }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/runFunction.R
runTestCase <- function(object_o_1, testCaseIndexes_i, evaluationMode_o_1 = EvaluationMode()) { determineFailureOrigin <- function(values_, frt_l_1, pc_l_1) { v <- c('code execution', 'value check', 'function return type check', 'parameter check') r <- v[c('error' %in% class(values_), isTRUE(frt_l_1), isTRUE(pc_l_1))] if (length(r) == 0) NA_character_ else strJoin(r) } compareValue <- function(a_1_, b_1_) { len <- c(length(a_1_), length(b_1_)) if (len[1] != len[2]) return(FALSE) if (len[1] == 0) return(typeof(a_1_) == typeof(b_1_)) rv <- sapply(seq_len(len[1]), function(k) { if (length(a_1_[k]) != 1) return(compareValue(a_1_[k], b_1_[k])) if (is.nan(a_1_[k])) return(is.nan(b_1_[k])) if (is.na(a_1_[k])) return(is.na(b_1_[k])) a_1_[k] == b_1_[k] }, simplify = FALSE) all(unlist(rv)) } tcd <- retrieveTestCaseDefinitions(object_o_1) ft <- tcd[testCaseIndexes_i] ems <- ifelse(evaluationMode_o_1$getEvaluationMode() == defineEvaluationModes()[1], 'standard_evaluation', 'type_checking_enforcement') l <- sapply(seq_len(nrow(ft)), function(k) { rf <- runFunction(object_o_1, ft[k]$function_name[[1]], ft[k]$test_case[[1]]$getParams(), evaluationMode_o_1) rf$index <- testCaseIndexes_i[k] vc <- compareValue(rf$value, ft[k]$test_case[[1]]$getExpectedResult()) rf$value_check <- vc rf$expected_evaluation <- unlist(ft[k, ems, with = FALSE], use.names = FALSE) fo <- determineFailureOrigin(rf$value, !rf$function_return_check, !rf$parameter_check) rf$execution_evaluation <- ifelse(is.na(fo), ifelse(vc, 'correct', 'erroneous'), 'failure') rf$failure_origin <- fo if ((ems == 'type_checking_enforcement') && (!is.na(fo) || !vc)) rf$status <- FALSE rf }, simplify = FALSE) names(l) <- ft$function_name pnames <- c('value', 'parameter_type_checks', 'function_return_type_check') syn <- rbindlist(lapply(l, function(e) e[which(!names(e) %in% pnames)])) cn <- colnames(syn) setcolorder(syn, c(cn[1:2], cn[5:6], cn[3:4], cn[7:9])) list(raw = l, synthesis = syn) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/runTestCase.R
runTransientFunction <- function(function_f_1, arguments_l, evaluationMode_o_1, function_return_type_s_1) { if (!is.function(function_f_1)) abort('unable to identify function', strBracket(function_f_1)) if (!is.list(arguments_l)) abort('arguments_l must be a list, got', strBracket(typeof(arguments_l))) buildResult <- function(status_b_1, value_, mode_s_1) { list(status = status_b_1, value = value_, mode = mode_s_1) } rv <- guardExecution(do.call(function_f_1, arguments_l)) modes <- defineEvaluationModes() if (evaluationMode_o_1$is(modes[1])) return(buildResult(TRUE, rv, modes[1])) b <- retrieveFactory()$verifyValue(FunctionParameterName(function_return_type_s_1[1]), rv) s <- buildResult(b$validity, rv, modes[2]) s$function_return_type_check <- rbindlist(list(b)) if (evaluationMode_o_1$is(modes[2])) return(s) mfa <- matchFunctionArguments(arguments_l, retrieveFunctionArgumentNames(function_f_1)) r <- buildResult(all(mfa$validity) && b$validity, rv, modes[3]) r$parameter_type_checks <- mfa r$function_return_type_check <- s$function_return_type_check r }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/runTransientFunction.R
verifyClassName <- function(name_s = 'MyClassName', strictSyntax_b_1 = TRUE) { verifyName(name_s, strictSyntax_b_1, FALSE) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyClassName.R
verifyFunctionArguments <- function(arguments_l, abort_b_1 = TRUE, verbosity_b_1 = FALSE) { l <- length(arguments_l) if (l == 0) return(TRUE) factory <- retrieveFactory() argument_names <- names(arguments_l) check <- lapply(seq_len(l), function(k) { factory$verifyValue(FunctionParameterName(argument_names[k]), arguments_l[[k]]) }) validity <- sapply(check, function(e) e$validity) if (verbosity_b_1) { print(arguments_l) # print(check) cat(paste(argument_names, validity, sapply(check, function(e) e$message), '\n'), '\n') } if (all(validity)) return(TRUE) if (abort_b_1) { w <- which(validity == FALSE) abort('argument mistmatch', strBracket(argument_names[w]), check[[w]]$message) } FALSE }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyFunctionArguments.R
verifyFunctionName <- function(name_s = 'aSimpleFunctionName', strictSyntax_b_1 = TRUE) { verifyName(name_s, strictSyntax_b_1, TRUE) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyFunctionName.R
verifyFunctionReturnTypesDefinition <- function(object_o_1, requiresFullInstrumentation_b_1 = TRUE) { buildReturnValue <- function(validity_b, intent_s, msg_s) { list(validity = validity_b, check = ifelse(requiresFullInstrumentation_b_1, 'full instrumentation check', 'partial instrumentation check'), class = getObjectClassNames(object_o_1)$classname, intent = intent_s, message = msg_s) } mef <- function(x_s) strBracket(strJoin(x_s)) verifyFormat <- function(sof_l) { brv <- function(validity_b, msg_s) { buildReturnValue(validity_b, 'function return types information format', msg_s) } if (!sof_l$frt) return(brv(FALSE, paste('no parameter', frtcn, 'definition in class'))) fn <- sof_l$instrumented_fn if (!data.table::is.data.table(fn)) return(brv(FALSE, paste('parameter', frtcn, 'wrongly instrumented in class. Must be a data.table'))) expected_column_names <- c('function_name', 'return_value') if (length(setdiff(expected_column_names, colnames(fn))) != 0) return(brv(FALSE, paste('wrong column name, got', mef(colnames(fn)), 'expected were', mef(expected_column_names)))) brv(TRUE, 'verified correct') } verifyContent <- function(sof_l) { brv <- function(validity_b, msg_s) { buildReturnValue(validity_b, 'function return types information content', msg_s) } fn <- sof_l$instrumented_fn if (length(unique(fn$function_name)) != length(fn$function_name)) return(brv(FALSE, 'unicity issue with declared function names')) ofn <- getObjectFunctionNames(object_o_1) sd <- setdiff(fn$function_name, ofn) if (length(sd) != 0) return(brv(FALSE, paste('unknown function name:', strJoin(strBracket(sd))))) sd <- setdiff(ofn, fn$function_name) if (requiresFullInstrumentation_b_1 && length(sd) != 0) return(brv(FALSE, paste('missing function declarations:', strJoin(strBracket(sd))))) rv <- unique(fn$return_value) # need to check that return_value is a known type cv <- sapply(rv, function(e) { FunctionParameterName(e)$isSemanticName() }, simplify = FALSE) if (any(cv == FALSE)) { w <- which(cv == FALSE) return(brv(FALSE, paste('wrong return value declaration', strBracket(rv[w])))) } brv(TRUE, 'verified correct') } sof <- retrieveSupportedObjectInformation(object_o_1) frtcn <- strBracket(defineFunctionReturnTypesParameterName()) rv <- verifyFormat(sof) if (!rv$validity) return(buildReturnValue(FALSE, paste(frtcn, 'format verification'), paste('failure', rv$intent, rv$message))) rv <- verifyContent(sof) if (!rv$validity) return(buildReturnValue(FALSE, paste(frtcn, 'content verification'), paste('failure', rv$intent, rv$message))) buildReturnValue(TRUE, 'naming and instrumentation format and content seems good', 'success') }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyFunctionReturnTypesDefinition.R
verifyName <- function(name_s = 'aSimpleName', strictSyntax_b_1 = TRUE, lowerCaseCamelized_b_1 = TRUE) { l <- length(name_s) if (l == 0) abort('you must provide a at least one name, got', l) if (!is.character(name_s)) abort('you must provide the name as a character, got,', class(name_s)) if (any(is.na(name_s))) abort('name can not take the NA value') fn <- destroySpaces(name_s) if (any(nchar(fn) == 0)) abort('you must provide the name as a non empty string, got,', strBracket(fn)) isValid <- function(aname_s) { if (strictSyntax_b_1) { first_letter <- substr(aname_s, 1, 1) if (lowerCaseCamelized_b_1 == TRUE & !first_letter %in% letters) return(FALSE) if (lowerCaseCamelized_b_1 == FALSE & !first_letter %in% LETTERS) return(FALSE) } pattern <- if (strictSyntax_b_1) '[A-Za-z0-9]+' else '[A-Za-z0-9_.]+' nchar(gsub(pattern, '', aname_s, perl = TRUE)) == 0 } ivv <- Vectorize(isValid) ivv(fn) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyName.R
verifyObjectNames <- function(object_o_1) { computeParameterNameCompliance <- function() { pn <- getObjectFunctionArgumentNames(object_o_1, FALSE) v <- sapply(seq_len(length(pn)), function(k) { if (length(pn[[k]]) != 0) { sapply(pn[[k]], function(e) { fpn <- FunctionParameterName(e) list(parameter_name = e, name_compliance_check = fpn$isValid(), semantic_naming_check = fpn$isSemanticName(), function_name = names(pn)[k]) }, simplify = FALSE) } else { list(list(parameter_name = NA_character_, name_compliance_check = TRUE, semantic_naming_check = TRUE, function_name = names(pn)[k])) } }, simplify = FALSE) dt <- data.table::rbindlist(unlist(v, recursive = FALSE)) s <- seq_len(ncol(dt)) data.table::setcolorder(dt, c(ncol(dt), s[-length(s)])) dt } sof <- retrieveSupportedObjectInformation(object_o_1) cn <- getObjectClassNames(object_o_1)$classname cct <- verifyClassName(cn, TRUE) ccf <- verifyClassName(cn, FALSE) ofn <- getObjectFunctionNames(object_o_1) if (length(ofn) > 0) { fcf <- verifyFunctionName(ofn, FALSE) fct <- verifyFunctionName(ofn, TRUE) pc <- computeParameterNameCompliance() snc <- cct && all(fct) && all(pc$semantic_naming_check) slc <- ccf && all(fcf) && all(pc$semantic_naming_check) } else { fct <- FALSE pc <- FALSE snc <- FALSE slc <- FALSE } missing_fn <- NA_character_ ifi <- if (sof$frt) { if (is.data.table(sof$instrumented_fn)) { defined_fn <- unique(pc$function_name) # catn('defined functions', strJoin(defined_fn)) # catn('instrumented functions', strJoin(instrumented_fn$function_name)) sd <- setdiff(defined_fn, sof$instrumented_fn$function_name) missing_fn <- ifelse(length(sd) == 0, 'none', strJoin(sd)) length(defined_fn) == nrow(sof$instrumented_fn) } else FALSE } else FALSE missing_tc <- NA_character_ itc <- if (sof$tcd) { if (is.data.table(sof$instrumented_tc)) { defined_tc <- unique(pc$function_name) #catn('defined test cases', strJoin(defined_tc)) ifn <- unique(sof$instrumented_tc$function_name) #catn('instrumented test cases', strJoin(ifn)) sd <- setdiff(defined_tc, ifn) missing_tc <- ifelse(length(sd) == 0, 'none', strJoin(sd)) length(defined_tc) == length(ifn) } else FALSE } else FALSE list(class_name_compliance = cct, function_name_compliance = fct, parameter_name_compliance = pc, classname = cn, owns_function_return_type_information = sof$frt, owns_test_case_definitions = sof$tcd, supports_strict_compliance = snc, supports_lazy_compliance = slc, can_be_typed_checked = sof$frt && (snc || slc), is_function_fully_instrumented = ifi, missing_functions = missing_fn, is_test_case_fully_instrumented = itc, missing_test_cases = missing_tc, sof = sof ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyObjectNames.R
verifyTestCaseDefinitions <- function(object_o_1, requiresFullInstrumentation_b_1 = TRUE) { buildReturnValue <- function(validity_b, intent_s, msg_s) { list(validity = validity_b, check = ifelse(requiresFullInstrumentation_b_1, 'full instrumentation check', 'partial instrumentation check'), class = getObjectClassNames(object_o_1)$classname, intent = intent_s, message = msg_s) } mef <- function(x_s) strBracket(strJoin(x_s)) verifyFormat <- function(sof_l) { brv <- function(validity_b, msg_s) { buildReturnValue(validity_b, 'test case definition format', msg_s) } # verify object name and type if (!sof_l$tcd) return(brv(FALSE, paste('no parameter', tcdcn, 'definition in class'))) tc <- sof_l$instrumented_tc if (!data.table::is.data.table(tc)) return(brv(FALSE, paste('apparently instrumented wrongly, expecting data.table, got type', mef(class(tc))))) # verify column names expected_column_names <- c('function_name', 'standard_evaluation', 'type_checking_enforcement', 'test_case') sd <- setdiff(colnames(tc), expected_column_names) if (length(sd) != 0) return(brv(FALSE, paste('wrong column names in data.table', mef(sd), 'expected column names are', mef(expected_column_names)))) # verify test case type typeCheck <- function(x) { sapply(x, function(e) { getObjectClassNames(e)$classname == 'TestCaseDefinition' }) } ch <- typeCheck(tc$test_case) if (!all(ch == TRUE)) return(brv(FALSE, paste('wrong type for test case declaration, entries', mef(which(ch != TRUE))))) brv(TRUE, 'test case declaration format verified as valid') } verifyContent <- function(sof_l) { brv <- function(validity_b, msg_s) { buildReturnValue(validity_b, 'test case definition content', msg_s) } tc <- sof_l$instrumented_tc # verify function names declared declared_functions <- getObjectFunctionNames(object_o_1) unknownFun <- setdiff(tc$function_name, declared_functions) uninstrumentedFun <- setdiff(declared_functions, tc$function_name) if (length(unknownFun) > 0) return(brv(FALSE, paste("unknown declared functions", mef(unknownFun)))) if (requiresFullInstrumentation_b_1 && length(uninstrumentedFun) > 0) return(brv(FALSE, paste("uninstrumented functions", mef(uninstrumentedFun)))) # verify expected status declarations allowed_expected_status <- c('correct', 'erroneous', 'failure') rv <- tc$standard_evaluation %in% allowed_expected_status if (any(rv == FALSE)) return(brv(FALSE, paste('wrong standard evaluation value', mef(tc$standard_evaluation[which(rv == FALSE)]), 'allowed values are', mef(allowed_expected_status)))) rv <- tc$type_checking_enforcement %in% allowed_expected_status if (any(rv == FALSE)) return(brv(FALSE, paste('wrong type checking enforcement value', mef(tc$type_checking_enforcement[which(rv == FALSE)]), 'allowed values are', mef((allowed_expected_status))))) brv(TRUE, 'test case declaration content verified as valid') } tcdcn <- strBracket(defineTestCaseDefinitionsParameterName()) sof <- retrieveSupportedObjectInformation(object_o_1) rv <- verifyFormat(sof) if (!rv$validity) return(buildReturnValue(FALSE, paste(tcdcn, 'format verification'), paste('failure', rv$intent, rv$message))) rv <- verifyContent(sof) if (!rv$validity) return(buildReturnValue(FALSE, paste(tcdcn, 'content verification'), paste('failure', rv$intent, rv$message))) buildReturnValue(TRUE, 'naming and instrumentation format and content seems good', 'success') }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/R/verifyTestCaseDefinitions.R
AdditionTCFIG1 <- function() { self <- environment() class(self) <- append('AdditionTCFIG1', class(self)) addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addMultiDouble <- function(...) as.double(sum(..., na.rm = TRUE)) addMultiInteger <- function(x_i, ...) x_i + sum(..., na.rm = TRUE) divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addDouble', 'addInteger', 'addMultiDouble', 'divideByZero', 'addMultiInteger', 'generateWarning', 'generateError'), return_value = c('x_d', 'x_i','x_d', 'x_d', 'x_i', 'x_w', 'x_er') ) test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError', rep('addMultiDouble', 3), rep('addMultiInteger', 3)), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure', rep('correct', 6)), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', # correct for generateWarning if options(warn = x < 2) 'failure', 'correct', 'correct', 'correct', 'correct', 'failure', 'correct' ), test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error'), #addMultiDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, 35L, 36L, NA_integer_), 105.0, 'sum of 1 double, 2 integers and 1 NA_integer_'), TestCaseDefinition(list(), 0, 'sum of nothing'), #addMultiInteger TestCaseDefinition(list(34L, 44L, 1L, 1L), 80L, 'sum of 4 integers'), TestCaseDefinition(list(34L, 35, 36, NA_integer_), 105, 'sum of 1 integer, 2 doubles and 1 NA_integer_'), TestCaseDefinition(list(34L), 34L, 'sum of one integer and nothing') ) ) label <- 'erroneous class instrumentation: test cases uses function divideByZero that is not instrumented for type checking enforcement' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/full/AdditionTCFIG1.R
AdditionTCFI_G1 <- function() { self <- environment() class(self) <- append('AdditionTCFI_G1', class(self)) addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addMultiDouble <- function(...) as.double(sum(..., na.rm = TRUE)) addMultiInteger <- function(x_i, ...) x_i + sum(..., na.rm = TRUE) divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addDouble', 'addInteger', 'addMultiDouble', 'divideByZero', 'addMultiInteger', 'generateWarning', 'generateError'), return_value = c('x_d', 'x_i','x_d', 'x_d', 'x_i', 'x_w', 'x_er') ) test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError', rep('addMultiDouble', 3), rep('addMultiInteger', 3)), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure', rep('correct', 6)), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', # correct for generateWarning if options(warn = x < 2) 'failure', 'correct', 'correct', 'correct', 'correct', 'failure', 'correct' ), test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error'), #addMultiDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, 35L, 36L, NA_integer_), 105.0, 'sum of 1 double, 2 integers and 1 NA_integer_'), TestCaseDefinition(list(), 0, 'sum of nothing'), #addMultiInteger TestCaseDefinition(list(34L, 44L, 1L, 1L), 80L, 'sum of 4 integers'), TestCaseDefinition(list(34L, 35, 36, NA_integer_), 105, 'sum of 1 integer, 2 doubles and 1 NA_integer_'), TestCaseDefinition(list(34L), 34L, 'sum of one integer and nothing') ) ) label <- 'erroneous class instrumentation: test cases uses function divideByZero that is not instrumented for type checking enforcement' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/full/AdditionTCFI_G1.R
AdditionTCFIP <- function() { self <- environment() class(self) <- append('AdditionTCFIP', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d = 0.0, ...) x_d + y_d + ... addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_ = 8L) 1:3 + 1:7 + x_ generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'divideByZero', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i','x_d', 'x_w', 'x_er') ) test_case_definitions <- data.table( function_name = c('addInteger', 'divideByZero', "divideByZero", 'generateWarning', 'generateError'), standard_evaluation = c('correct', 'correct', 'correct', 'correct', 'failure'), type_checking_enforcement = c('erroneous', 'correct', 'correct', 'correct', 'correct'), test_case = list( # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/partial/AdditionTCFIP.R
Addition_TCFI_Partial_R6 <- R6::R6Class("Addition_TCFI_Partial_R6", list( sum = 0, addInteger = function(x_i, y_i) { x_i + y_i }, generateError = function() { stop('generated error')}, generateWarning = function() 1:3 + 1:7, function_return_types = data.table( function_name = c('addInteger', 'generateError'), return_value = c('x_n', 'x_er') ), test_case_definitions = data.table( function_name = c(rep('addInteger', 9), 'generateError'), standard_evaluation = c(rep('correct', 4), 'erroneous', rep('correct', 4), 'failure'), type_checking_enforcement = c(rep('correct', 4), rep('failure', 5), 'failure'), test_case = list( #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ), label = 'R6 partial instrumentation' ))
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/partial/Addition_TCFI_Partial_R6.R
Addition_TCFI_Partial_RC <- setRefClass("Addition_TCFI_Partial_RC", fields = list(function_return_types = "data.table", test_case_definitions = "data.table", label = 'character'), methods = list( initialize = function() { function_return_types <<- data.table( function_name = c('addInteger', 'generateError', 'generateWarning'), return_value = c('x_n', 'x_n', 'x_er') ) test_case_definitions <<- data.table( function_name = c(rep('addInteger', 9), 'generateError', 'generateErrorBis'), standard_evaluation = c(rep('correct', 4), 'erroneous', rep('correct', 4), 'failure', 'failure'), type_checking_enforcement = c(rep('correct', 4), rep('failure', 5), 'failure', 'failure'), test_case = list( #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # generateError TestCaseDefinition(list(), NA, 'generate error'), # generateErrorBis TestCaseDefinition(list(), NA, 'generate error bis') ) ) label <<- 'R6 partial instrumentation' }, addInteger = function(x_i, y_i) { x_i + y_i }, generateWarning = function() 1:3 + 1:7, generateError = function() { stop('generated error')}, generateErrorBis = function() { stop('generated error bis')} ) )
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/partial/Addition_TCFI_Partial_RC.R
Addition_TCFI_Partial_S3 <- function() { value <- list() attr(value, 'class') <- 'Addition_TCFI_Partial_S3' # only 4 functions are recorded as generic, 2 are declared here # ==> partial verifications will be ok, full verifications will be ko value$function_return_types <- data.table( function_name = c('addNumeric', 'generateError'), return_value = c('x_n', 'x_er') ) value$test_case_definitions <- data.table( function_name = c(rep('addInteger', 9), 'generateError'), standard_evaluation = c(rep('correct', 4), 'erroneous', rep('correct', 4), 'failure'), type_checking_enforcement = c(rep('correct', 4), rep('failure', 5), 'failure'), test_case = list( #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) value$label <- 'partial instrumentation of S3 - Should work with type checking enforcement' value } addNumeric <- function(object_o_1, x_n, y_n) UseMethod('addNumeric', object_o_1) addNumeric.Addition_TCFI_Partial_S3 <- function(object_o_1, x_n, y_n) x_n + y_n addDouble.Addition_TCFI_Partial_S3 <- function(object_o_1, x_d, y_d) x_d + y_d addInteger <- function(object_o_1, x_i, y_i) UseMethod('addInteger', object_o_1) addInteger.Addition_TCFI_Partial_S3 <- function(object_o_1, x_i, y_i) x_i + y_i divideByZero.Addition_TCFI_Partial_S3 <- function(object_o_1, x_n) x_n / 0 generateWarning.Addition_TCFI_Partial_S3 <- function(object_o_1) 1:3 + 1:7 generateWarning2.Addition_TCFI_Partial_S3 <- function(object_o_1) 1:3 + 1:7 generateWarning2 <- function(object_o_1, x_n, y_n) UseMethod('generateWarning2', object_o_1) generateError <- function(object_o_1) UseMethod('generateError', object_o_1) generateError.Addition_TCFI_Partial_S3 <- function(object_o_1) stop('generated error') # a <- Addition_TCFI_Partial_S3() # print(addNumeric(a, 3, 4.1)) # print(addNumeric.Addition_TCFI_Partial_S3(a, 3, 4.1)) # #print(a.addNumeric(3, 4.1)) # methods(class = 'Addition_TCFI_Partial_S3') # methods('addNumeric') # # print(addDouble.Addition_TCFI_Partial_S3(a, 3, 4.1)) # Reminder # Calling a method directly is possible, generic or not. Use <methodName>.<className>(object, arguments, ...) # Calling a generic method is possible. Use <methodName>(object, arguments, ...) # # Code transformation # Need an extraneous argument as first argument to function call, that is the object to consider #
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/partial/Addition_TCFI_Partial_S3.R
Addition_TCFI_Partial_S4 <- setClass("Addition_TCFI_Partial_S4", slots = c( function_return_types = "data.table", test_case_definitions = "data.table" ) ) setMethod("initialize", "Addition_TCFI_Partial_S4", function(.Object, ...) { .Object <- callNextMethod() .Object@function_return_types <- data.table( function_name = c('addInteger', 'generateError'), return_value = c('x_n', 'x_er') ) .Object@test_case_definitions <- data.table( function_name = c(rep('addInteger', 9), 'generateError'), standard_evaluation = c(rep('correct', 4), 'erroneous', rep('correct', 4), 'failure'), type_checking_enforcement = c(rep('correct', 4), rep('failure', 5), 'failure'), test_case = list( #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) #cat("Addition_TCFI_Partial_S4 initialized\n") .Object }) setGeneric(name = "addNumeric", def = function(object_o_1, x_d, y_d) standardGeneric("addNumeric")) setMethod(f = "addNumeric", signature = "Addition_TCFI_Partial_S4", definition = function(object_o_1, x_d, y_d) x_d + y_d ) setGeneric(name = "addInteger", def = function(object_o_1, x_i, y_i) standardGeneric("addInteger")) setMethod(f = "addInteger", signature = "Addition_TCFI_Partial_S4", definition = function(object_o_1, x_i, y_i) x_i + y_i ) setGeneric(name = "generateWarning", def = function(object_o_1, x_i, y_i) standardGeneric("generateWarning")) setMethod(f = "generateWarning", signature = "Addition_TCFI_Partial_S4", definition = function(object_o_1) 1:3 + 1:7 ) setGeneric(name = "generateError", def = function(object_o_1) standardGeneric("generateError")) setMethod(f = "generateError", signature = "Addition_TCFI_Partial_S4", definition = function(object_o_1) stop('generated error') ) # setMethod("addDouble", "Addition_TCFI_Partial_S4", function(object_o_1, x_d, y_d, ...) x_d + y_d) # setMethod("divideByZero", "Addition_TCFI_Partial_S4", function(object_o_1, x_n, ...) x_n / 0)
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/both-defs/good/partial/Addition_TCFI_Partial_S4.R
Accumulator_R6 <- R6::R6Class("Accumulator_R6", list( sum = 0, add = function(x = 1) { self$sum <- self$sum + x self$sum }) ) EmptyR6 <- R6::R6Class("EmptyR6", list()) FieldR6 <- R6::R6Class("FieldR6", list(alpha = 4.4)) MethodR6 <- R6::R6Class("MethodR6", list(alpha = function() Inf)) BindingR6 <- R6::R6Class("BindingR6", private = list(x = 1000L), active = list(z = function(x_i) { if (missing(x_i)) return(private$x) private$x <- as.integer(x_i) })) Bu_S3 <- function(x_l = list(l = letters, d = 0:9)) { value <- x_l attr(value, 'class') <- 'Bu_S3' value } alpha <- function(x, msg_s = '', ...) { UseMethod('alpha') } alpha.Bu_S3 <- function(x, msg_s = '', ...) { paste("in alpha.Bu_S3", class(x), msg_s, ...) } EmptyS3 <- function() { value <- list() attr(value, 'class') <- 'EmptyS3' invisible(value) } FieldS3 <- function(x_b = list(a = 1L)) { value <- x_b attr(value, 'class') <- 'FieldS3' invisible(value) } MethodS3 <- function(x_l = list()) { value <- x_l attr(value, 'class') <- 'MethodS3' invisible(value) } value <- function(x, ...) { UseMethod('value') } value.MethodS3 <- function(x, ...) { x$value } Unknown <- function() { value <- 1L attr(value, 'class') <- 'Unknown' invisible(value) } # alpha(b, "ici", 'là', 'et là-bas') # [1] "in alpha.Bu_S3 Bu_S3 ici là et là-bas" print.Bu_S3 <- function(x, ...) { print.default(x, ...) } getRObjectFromClassKind <- function(classkind_s_1) { switch(toupper(classkind_s_1[1]), 'R6' = Accumulator_R6$new(), 'RC' = Person_RC(name = 'neonira'), 'S4' = Person_S4(name = 'neonira'), 'ENV' = MeltingPot_Env(), 'S3' = Bu_S3(), NULL ) } MeltingPot_Env <- function() { self <- environment() class(self) <- append('MeltingPot_Env', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addMultiDouble <- function(...) as.double(sum(..., na.rm = TRUE)) addMultiInteger <- function(x_i, ...) x_i + sum(..., na.rm = TRUE) add3length <- function(x_i_3l, y_i_3l = 1:3) x_i_3l + y_i_3l divideByZero <- function(x_n) x_n / 0 generateWarning <- function() 1:3 + 1:7 generateError <- function() stop('generated error') echo <- function(x_s = 'hello world') { x_s } blabla <- function(a_s = 'bla', b_s = c('bli', 'blo', 'blu')) paste(a_s, b_s) self } Person_RC <- setRefClass("Person_RC", fields = list(name = "character", age = "integer"), methods = list( setName = function(aname) { name <<- aname }, setAge = function(anAge) { age <<- anAge } ) ) EmptyRC <- setRefClass("EmptyRC", fields = list(), methods = list() ) FieldRC <- setRefClass("FieldRC", fields = list(x = 'integer'), methods = list() ) MethodRC <- setRefClass("MethodRC", fields = list(), methods = list( getString = function() { paste(sample(letters, 7, TRUE), collapse = '\n') } ) ) Person_S4 <- setClass("Person_S4", slots = c( name = "character", age = "numeric" ) ) setMethod("show", "Person_S4", function(object) { cat(is(object)[[1]], "\n", " Name: ", object@name, "\n", " Age: ", object@age, "\n", sep = "" ) }) setGeneric("name", function(o_) standardGeneric("name")) setMethod("name", "Person_S4", function(o_) o_@name) #showMethods(class='Person_S4', includeDefs = TRUE) FieldS4 <- setClass("FieldS4", slots = c( name = "character", age = "numeric" ) ) # no slot implies virtual and non reifiability VirtualS4 <- setClass("VirtualS4") MethodS4 <- setClass("MethodS4", slots = c(a = 'numeric')) setGeneric("info", function(x_) standardGeneric("info")) setMethod('info', signature(x_ = "MethodS4"), function(x_) 43L) MyEnv <- function() { self <- environment() class(self) <- append('MyEnv', class(self)) f <- function(x_d) x_d self } EmptyEnv <- function() { self <- environment() class(self) <- append('EmptyEnv', class(self)) self } FieldEnv <- function() { self <- environment() x <- 4L class(self) <- append('FieldEnv', class(self)) self } MethodEnv <- function() { self <- environment() fun <- function() 444L class(self) <- append('MethodEnv', class(self)) self } Zorg <- function() { self <- environment() class(self) <- append('Zorg', class(self)) h <- f <- function(x_d) x_d function_name <- NULL # data.table NSE issue with Rcmd check function_return_types <- data.table( function_name = c('f'), return_value = c('x_d') )[order(function_name)] self } # wrong column name in data.table Zarg <- function() { self <- environment() class(self) <- append('Zarg', class(self)) h <- f <- function(x_d) x_d function_return_types <- data.table( function_names = c('f'), return_value = c('x_d') ) self } # wrong test case definition - none is an unallowed keyword for standard_evaluation Zurg <- function() { self <- environment() class(self) <- append('Zurg', class(self)) h <- f <- function(x_d) x_d test_case_definitions <- data.table( function_name = c('f'), standard_evaluation = c('none'), type_checking_enforcement = c('correct'), test_case = list( TestCaseDefinition(list(34), 34, 'f nominal') ) ) self } # wrong test case definition - none is an unallowed keyword for type_checking_enforcement Zirg <- function() { self <- environment() class(self) <- append('Zirg', class(self)) h <- f <- function(x_d) x_d test_case_definitions <- data.table( function_name = c('f'), standard_evaluation = c('correct'), type_checking_enforcement = c('none'), test_case = list( TestCaseDefinition(list(34), 34, 'f nominal') ) ) self } Wyx <- function(d_d, y_b_1 = FALSE) { self <- environment() class(self) <- append('Wyx', class(self)) h <- f <- function(x_d) x_d + d_d self } PureR <- function() { self <- environment() class(self) <- append('PureR', class(self)) h <- f <- function(x) x self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/classes/sample-classes.R
AdditionFIW1 <- function() { self <- environment() class(self) <- append('AdditionFIW1', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'addInteger', 'addMultiInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i_1', 'x_i', 'x_i', 'x_') ) label <- 'erroneous function return type definition - provided function names are not unique' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFIW1.R
AdditionFIW2 <- function() { self <- environment() class(self) <- append('AdditionFIW2', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'addInteger1', 'addMultiInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i_1', 'x_i', 'x_i', 'x_') ) label <- 'erroneous function return type definition - unknown function names' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFIW2.R
AdditionFIW3 <- function() { self <- environment() class(self) <- append('AdditionFIW3', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i', 'x') ) label <- 'erroneous function return type definition - unknown return type x' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFIW3.R
AdditionFIW4 <- function() { self <- environment() class(self) <- append('AdditionFIW4', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- list( function_name = c('addNumeric', 'addDouble', 'addInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i_1', 'x_i', 'x_i', 'x') ) label <- 'erroneous function return type definition - list instead of data.table' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFIW4.R
AdditionFI_W1 <- function() { self <- environment() class(self) <- append('AdditionFI_W1', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'addInteger', 'addMultiInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i_1', 'x_i', 'x_i', 'x_') ) label <- 'erroneous function return type definition - provided function names are not unique' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFI_W1.R
AdditionFI_W2 <- function() { self <- environment() class(self) <- append('AdditionFI_W2', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'addInteger1', 'addMultiInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i_1', 'x_i', 'x_i', 'x_') ) label <- 'erroneous function return type definition - unknown function names' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFI_W2.R
AdditionFI_W3 <- function() { self <- environment() class(self) <- append('AdditionFI_W3', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i', 'x') ) label <- 'erroneous function return type definition - unknown return type x' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFI_W3.R
AdditionFI_W4 <- function() { self <- environment() class(self) <- append('AdditionFI_W4', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- list( function_name = c('addNumeric', 'addDouble', 'addInteger', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_i', 'x_i_1', 'x_i', 'x_i', 'x') ) label <- 'erroneous function return type definition - list instead of data.table' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/bad/AdditionFI_W4.R
AdditionFI <- function() { self <- environment() class(self) <- append('AdditionFI', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addMultiDouble <- function(...) sum(..., na.rm = TRUE) addInteger <- function(x_i, y_i) x_i + y_i addMultiInteger <- function(x_i, ...) x_i + sum(..., na.rm = TRUE) add3length <- function(x_i_3l, y_i_3l = 1:3) x_i_3l + y_i_3l divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addMultiDouble', 'addInteger', 'addMultiInteger', 'add3length', 'divideByZero', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_d', 'x_i', 'x_i', 'x_i_3l', 'x_d', 'x_w', 'x_e') )[order(function_name)] self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/good/full/AdditionFI.R
AdditionFI_ <- function() { self <- environment() class(self) <- append('AdditionFI_', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addMultiDouble <- function(...) sum(..., na.rm = TRUE) addInteger <- function(x_i, y_i) x_i + y_i addMultiInteger <- function(x_i, ...) x_i + sum(..., na.rm = TRUE) add3length <- function(x_i_3l, y_i_3l = 1:3) x_i_3l + y_i_3l divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addMultiDouble', 'addInteger', 'addMultiInteger', 'add3length', 'divideByZero', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_d', 'x_i', 'x_i', 'x_i_3l', 'x_d', 'x_w', 'x_e') )[order(function_name)] self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/good/full/AdditionFI_.R
AdditionFIPartial <- function() { self <- environment() class(self) <- append('AdditionFIPartial', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addMultiDouble <- function(...) sum(..., 0.0, na.rm = TRUE) addInteger <- function(x_i, y_i) x_i + y_i addMultiInteger <- function(x_i, ...) x_i + sum(..., 0L, na.rm = TRUE) add3length <- function(x_i_3l, y_i_3l = 1:3) x_i_3l + y_i_3l divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addMultiDouble', 'addInteger', 'addMultiInteger', 'add3length', 'generateWarning', 'generateError'), return_value = c('x_n', 'x_d', 'x_d', 'x_i', 'x_i', 'x_i_3l', 'x_w', 'x_e') )[order(function_name)] self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/good/partial/AdditionFIPartial.R
AdditionFI_Partial <- function() { self <- environment() class(self) <- append('AdditionFI_Partial', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addMultiDouble <- function(...) sum(..., na.rm = TRUE) addInteger <- function(x_i, y_i) x_i + y_i addMultiInteger <- function(x_i, ...) x_i + sum(..., na.rm = TRUE) add3length <- function(x_i_3l, y_i_3l = 1:3) x_i_3l + y_i_3l add3segments <- function(x_i_3l, y_i_3l = 1:3, z_i_3l) x_i_3l + y_i_3l + z_i_3l divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') function_return_types <- data.table( function_name = c('addNumeric', 'addDouble', 'addMultiDouble', 'addInteger', 'addMultiInteger', 'add3length', 'generateWarning', 'generateError', 'add3segments'), return_value = c('x_n', 'x_d', 'x_d', 'x_i', 'x_i', 'x_i_3l', 'x_w', 'x_e', 'x_i_3l') )[order(function_name)] self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/frt-defs/good/partial/AdditionFI_Partial.R
#' a sample class #' @return environment #' @examples #' a <- Addition() Addition <- function() { self <- environment() class(self) <- append('Addition', class(self)) addNumeric <- function(x, y_n) x + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_ = 0L) 1:3 + 1:7 + x_ generateError <- function() stop('generated error') self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/no-defs/Addition.R
Addition_S3 <- function(x_l = list()) { value <- x_l attr(value, 'class') <- 'Addition_S3' value } addNumeric <- function(o_, x_n, y_n) UseMethod('addNumeric', o_) addNumeric.Addition_S3 <- function(o, x_n, y_n) x_n + y_n addDouble.Addition_S3 <- function(o, x_d, y_d) x_d + y_d addInteger.Addition_S3 <- function(o, x_i, y_i) x_i + y_i divideByZero.Addition_S3 <- function(o, x_n) x_n / 0 generateWarning.Addition_S3 <- function(o, x_ = 0L) 1:3 + 1:7 + x_ generateError.Addition_S3 <- function() stop('generated error')
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/no-defs/Addition_S3.R
Addition_S3_NoGeneric <- function(x_l = list()) { value <- x_l attr(value, 'class') <- 'Addition_S3_NoGeneric' value } addInteger.Addition_S3_NoGeneric <- function(x_i, y_i) x_i + y_i addNumeric.Addition_S3_NoGeneric <- function(x_n, y_n) x_n + y_n addDouble.Addition_S3_NoGeneric <- function(x_d, y_d) x_d + y_d divideByZero.Addition_S3_NoGeneric <- function(x_n) x_n / 0 generateWarning.Addition_S3_NoGeneric <- function(x_ = 0L) 1:3 + 1:7 + x_ generateError.Addition_S3_NoGeneric <- function() stop('generated error')
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/no-defs/Addition_S3_NoGeneric.R
AdditionTCW1 <- function() { self <- environment() class(self) <- append('AdditionTCW1', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } testCases <- list( addDouble = list( correct = list( TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NA_real_, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf') ), erroneous = list( TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation') ), failure = list( TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA') ) ), addInteger1 = list( correct = list( TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer') ), # erroneous = list( # TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80L, 'sum 2 as.integers confused with sum of rounded value as expectation') # ), failure = list( TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer') ), tmp = list( TestCaseDefinition(list(3+5i, 44), , 'sum a vector of 1 complex integers with 1 integer') ) ) ) label <- 'erroneous test case definition: wrong test case definition keyword' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTCW1.R
AdditionTCW2 <- function() { self <- environment() class(self) <- append('AdditionTCW2', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } test_case_definitions <- list( addDouble = list( correct = list( TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NA_real_, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf') ), erroneous = list( TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation') ), failure = list( TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA') ) ), addInteger1 = list( correct = list( TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer') ), # erroneous = list( # TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80L, 'sum 2 as.integers confused with sum of rounded value as expectation') # ), failure = list( TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer') ), tmp = list( TestCaseDefinition(list(3+5i, 44), , 'sum a vector of 1 complex integers with 1 integer') ) ) ) label <- 'erroneous test case definition: wrong type, not a data.table' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTCW2.R
AdditionTCW3 <- function() { self <- environment() class(self) <- append('AdditionTCW3', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_eval = c(rep('correct', 5), 'z', rep('correct', 7), 'wrong', rep('correct', 8), 'failure'), type_check_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), list(NA, NA), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 2:8, 'generate warning'), # generateError TestCaseDefinition(list(0), 0, 'generate error') ) ) label <- 'erroneous test case definition: wrong data.table column name' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTCW3.R
AdditionTCW4 <- function() { self <- environment() class(self) <- append('AdditionTCW4', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } test_case_definitions <- list( addDouble = list( correct = list( TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NA_real_, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf') ), erroneous = list( TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation') ), failure = list( TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), list(list(NA, NA), NA, 'sum 2 NA') ) ), addInteger1 = list( correct = list( TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer') ), # erroneous = list( # TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80L, 'sum 2 as.integers confused with sum of rounded value as expectation') # ), failure = list( TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer') ) ) ) label <- 'erroneous test case definition: wrong type for TestCaseDefinition' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTCW4.R
AdditionTCW5 <- function() { self <- environment() class(self) <- append('AdditionTCW5', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) suppressWarnings(1:3 + 1:7) generateError <- function(x_) { stop('generated error'); x_ } test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'z', rep('correct', 7), 'wrong', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), list(NA, NA), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 2:8, 'generate warning'), # generateError TestCaseDefinition(list(0), 0, 'generate error') ) ) label <- 'erroneous test case definition: unknown evaluation keyword' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTCW5.R
AdditionTCW6 <- function() { self <- environment() class(self) <- append('AdditionTCW6', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) suppressWarnings(1:3 + 1:7) generateError <- function(x_) { stop('generated error'); x_ } test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZer', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum of two NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 2:8, 'generate warning'), # generateError TestCaseDefinition(list(0), 0, 'generate error') ) ) label <- 'erroneous test case definition: unknown function' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTCW6.R
AdditionTC_W1 <- function() { self <- environment() class(self) <- append('AdditionTC_W1', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } testCases <- list( addDouble = list( correct = list( TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NA_real_, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf') ), erroneous = list( TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation') ), failure = list( TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA') ) ), addInteger1 = list( correct = list( TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer') ), # erroneous = list( # TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80L, 'sum 2 as.integers confused with sum of rounded value as expectation') # ), failure = list( TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer') ), tmp = list( TestCaseDefinition(list(3+5i, 44), , 'sum a vector of 1 complex integers with 1 integer') ) ) ) label <- 'erroneous test case definition: wrong test case definition keyword' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTC_W1.R
AdditionTC_W2 <- function() { self <- environment() class(self) <- append('AdditionTC_W2', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } test_case_definitions <- list( addDouble = list( correct = list( TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NA_real_, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf') ), erroneous = list( TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation') ), failure = list( TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA') ) ), addInteger1 = list( correct = list( TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer') ), # erroneous = list( # TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80L, 'sum 2 as.integers confused with sum of rounded value as expectation') # ), failure = list( TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer') ), tmp = list( TestCaseDefinition(list(3+5i, 44), , 'sum a vector of 1 complex integers with 1 integer') ) ) ) label <- 'erroneous test case definition: wrong type, not a data.table' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTC_W2.R
AdditionTC_W3 <- function() { self <- environment() class(self) <- append('AdditionTC_W3', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_eval = c(rep('correct', 5), 'z', rep('correct', 7), 'wrong', rep('correct', 8), 'failure'), type_check_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), list(NA, NA), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 2:8, 'generate warning'), # generateError TestCaseDefinition(list(0), 0, 'generate error') ) ) label <- 'erroneous test case definition: wrong data.table column name' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTC_W3.R
AdditionTC_W4 <- function() { self <- environment() class(self) <- append('AdditionTC_W4', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i addInteger1 <- function(x_i_1, y_i_1) x_i_1 + y_i_1 addMultiInteger <- function(x_i, y_i, z_i = 0, k_i = 0, ...) { x_i + y_i + z_i + k_i + sum(..., na.rm = TRUE) } test_case_definitions <- list( addDouble = list( correct = list( TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NA_real_, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf') ), erroneous = list( TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation') ), failure = list( TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), list(list(NA, NA), NA, 'sum 2 NA') ) ), addInteger1 = list( correct = list( TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer') ), # erroneous = list( # TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80L, 'sum 2 as.integers confused with sum of rounded value as expectation') # ), failure = list( TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer') ) ) ) label <- 'erroneous test case definition: wrong type for TestCaseDefinition' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTC_W4.R
AdditionTC_W5 <- function() { self <- environment() class(self) <- append('AdditionTC_W5', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) suppressWarnings(1:3 + 1:7) generateError <- function(x_) { stop('generated error'); x_ } test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'z', rep('correct', 7), 'wrong', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), list(NA, NA), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 2:8, 'generate warning'), # generateError TestCaseDefinition(list(0), 0, 'generate error') ) ) label <- 'erroneous test case definition: unknown evaluation keyword' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTC_W5.R
AdditionTC_W6 <- function() { self <- environment() class(self) <- append('AdditionTC_W6', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) suppressWarnings(1:3 + 1:7) generateError <- function(x_) { stop('generated error'); x_ } test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZer', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum of two NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 2:8, 'generate warning'), # generateError TestCaseDefinition(list(0), 0, 'generate error') ) ) label <- 'erroneous test case definition: unknown function' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/bad/AdditionTC_W6.R
AdditionTC <- function() { self <- environment() class(self) <- append('AdditionTC', class(self)) addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/good/full/AdditionTC.R
AdditionTC_ <- function() { self <- environment() class(self) <- append('AdditionTC_', class(self)) addDouble <- function(x_d, y_d) x_d + y_d addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_) 1:3 + 1:7 generateError <- function() stop('generated error') test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/good/full/AdditionTC_.R
AdditionTCPartial <- function() { self <- environment() class(self) <- append('AdditionTCPartial', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d = 0.0, ...) x_d + y_d + ... addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_ = 8L) 1:3 + 1:7 + x_ generateError <- function() stop('generated error') test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/good/partial/AdditionTCPartial.R
AdditionTC_Partial <- function() { self <- environment() class(self) <- append('AdditionTC_Partial', class(self)) addNumeric <- function(x_n, y_n) x_n + y_n addDouble <- function(x_d, y_d = 0.0, ...) x_d + y_d + ... addInteger <- function(x_i, y_i) x_i + y_i divideByZero <- function(x_n) x_n / 0 generateWarning <- function(x_ = 8L) 1:3 + 1:7 + x_ generateError <- function() stop('generated error') test_case_definitions <- data.table( function_name = c(rep('addDouble', 9), rep('addInteger', 9), rep('divideByZero', 3), 'generateWarning', 'generateError'), standard_evaluation = c(rep('correct', 5), 'erroneous', rep('correct', 7), 'erroneous', rep('correct', 8), 'failure'), type_checking_enforcement = c(rep('correct', 5), 'erroneous', rep('failure', 3), rep('correct', 4), rep('failure', 5), rep('correct', 3), 'correct', 'erroneous'), # correct for generateWarning if options(warn = x < 2) test_case = list( #addDouble TestCaseDefinition(list(as.double(34L), 44.5), 78.5, 'sum 2 doubles'), TestCaseDefinition(list(34.0, NA_real_), NA_real_, 'sum 1 double and 1 NA_real_'), TestCaseDefinition(list(NA_real_, NA_real_), NA_real_, 'sum 2 NA_real_'), TestCaseDefinition(list(NaN, NaN), NaN, 'sum 2 NAN'), TestCaseDefinition(list(Inf, Inf), Inf, 'sum 2 Inf'), #addDouble - se => erroneous TestCaseDefinition(list(as.integer(34.7), as.integer(44.9)), 80, 'sum 2 as.integers confused with sum of rounded value as expectation'), #addDouble TestCaseDefinition(list(34L, 44.5), 78.5, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(34.0, NA_integer_), NA_real_, 'sum of 1 integer and 1 double'), TestCaseDefinition(list(NA, NA), NA, 'sum 2 NA'), #addInteger - correct TestCaseDefinition(list(34L, as.integer(44.5)), 78L, 'sum 2 integers'), TestCaseDefinition(list(34L, NA_integer_), NA_integer_, 'sum 1 integer and 1 NA_integer'), TestCaseDefinition(list(NA_integer_, NA_integer_), NA_integer_, 'sum 2 NA_integer'), TestCaseDefinition(list(as.integer("45.654"), 44L), 89L, 'sum a converted string with one integer'), # addInteger - se => erroneous, tci => failure TestCaseDefinition(list(34L, 44.5), 78L, 'sum 1 integer and 1 double'), # addInteger - se => correct, tci => failure TestCaseDefinition(list(34L, Inf), Inf, 'sum 1 integer and 1 Inf'), TestCaseDefinition(list(34L, NaN), NaN, 'sum 1 integer and 1 NAN'), TestCaseDefinition(list(34L, NA), NA, 'sum 1 integer and 1 NA'), TestCaseDefinition(list(c(34L, 35L), 44L), c(78L, 79L), 'sum a vector of 2 integers with 1 integer'), # divideByZero - correct TestCaseDefinition(list(1), Inf, '1 / 0'), TestCaseDefinition(list(-1), -Inf, '-1 / 0'), TestCaseDefinition(list(0), NaN, '0 / 0'), # generateWarning TestCaseDefinition(list(0), 1:3 + 1:7, 'generate warning'), # generateError TestCaseDefinition(list(), NA, 'generate error') ) ) self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/code-samples/tcd-defs/good/partial/AdditionTC_Partial.R
## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "") source('common-style.R')
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/doc/release-notes.R
--- title: "wyz.code.offensiveProgramming releases" author: "Fabien GELINEAU" date: "last update on 2020-04-19" output: rmarkdown::html_vignette: css: style.css number_sections: true toc: false vignette: > %\VignetteIndexEntry{wyz.code.offensiveProgramming releases} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- <img src='images/op-hex.png' alt='offensive programming' style='width:30%'/> ```{r setup, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "") source('common-style.R') ``` # name [awesome-asterion-omega] package-version [1.1.24] timestamp [2023-09-25 08:27:33] 1. CRAN notes about Rd files requires adaptations 1. Changed `r citefile("retrieveTestCaseDefinitions.rd")` and `r citefile("retrieveFunctionReturnTypes.R")` # name [awesome-asterion-psi] package-version [1.1.23] timestamp [2021-10-05 22:58:54] 1. CRAN 3 notes 1. DESCRIPTION change URL - added an ending / as it seemed required 1. removed lazydata as there is no data folder 1. On :`r citefile("FunctionParameterTypeFactory.R")` conditionned example run. Kept only for unix systems. # name [awesome-asterion-khi] package-version [1.1.22] timestamp [2021-10-05 20:17:45] 1. CRAN information on obsolescence of lubridate - need to remove dependency. 1. lubridate::date() was used in file `r citefile("FunctionParameterTypeFactory.R")`. <pre> FunctionParameterTypeFactory.R: list('da' , 'date' , list(lubridate::is.Date) , type_classes$date), FunctionParameterTypeFactory.R: list('dc' , 'POSIXct' , list(lubridate::is.POSIXct) , type_classes$date), FunctionParameterTypeFactory.R: list('dl' , 'POSIXlt' , list(lubridate::is.POSIXlt) , type_classes$date), </pre> 1. Test, Duration: `r citefigure('7.7s')`, OK: `r citefigure('450')` 1. `r citeexec('R CMD check')`, Duration: `r citefigure('32.1s')`, 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 1. `r citeval('Commercial software release management')` 1. `r citefolder('vignette')` content update 1. `r citeop("git")` alignment # name [awesome-asterion-phi] package-version [1.1.21] timestamp [2020-11-09 19:57:38] 1. enforced R 4.0 1. Test, Duration: `r citefigure('7.3s')`, OK: `r citefigure('450')` 1. `r citeexec('R CMD check')`, Duration: `r citefigure('33.8s')`, 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 1. `r citeval('Commercial software release management')` 1. `r citefolder('vignette')` content update 1. `r citeop("git")` alignment # 1. modified implementation `r citefun("matchFunctionArguments")` function to solve aborption issue when called with empty parameter list. 1. modified `r citefun("FunctionParameterTypeFactory")` function. Added cantor real type. Latest release replaces fully older ones, that are now considered obsoletes. Keep the pace, and upgrade your packages to use the latest version! # Release awesome-asterion-tau - 1.1.19 - 2020-05-04 1. Test, Duration: `r citefigure('7.1s')`, OK: `r citefigure('450')` 1. `r citeexec('R CMD check')`, Duration: `r citefigure('33.8s')`, 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 1. `r citeval('Commercial software release management')` 1. `r citefolder('vignette')` structure update 1. `r citefolder('vignette')` content update # Release 1.1.18 - awesome-asterion-sigma - 2005-05-04 Main improvements are 1. polished all `r citeit('R')` `r citefile('.Rd')` documentation files 1. R code - `r citefigure(34)` exported functions, `r citefigure(6)` internals 1. manual pages - `r citefigure(36)` files 1. tests - `r citefigure(36)` files 1. vignettes - `r citefigure(1)` files 1. code as data - `r citefigure(39)` files 1. Timing: tests 8s Duration: `r citefigure('7.2s')` for `r citefigure('450')` tests 1. R CMD check results ─ wyz.code.offensiveProgramming 1.1.18 ─ Duration: `r citefigure('37.1s')` - 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ # Release 1.1.17 Main improvements are 1. removed environment variable `r citecode("OP_TYPE_FACTORY")` management. Replaced by `r citecode("options('op_type_factory')")` 1. removed environment variable `r citecode("OP_AUDIT")` management. Replaced by `r citecode("options('op_audit')")` 1. removed default valued argument `r citecode("functionParameterTypeFactory_o_1 = retrieveFactory()")` from many functions, as it is useless and can be directly accessed/determined by the code. 1. Changed field `r citeop('function_name')` to `r citeop('name')` in `r citefun('packageFunctionsInformation')` for consistency reasons 1. `r citefun('packageFunctionsInformation')` renamed to `r citefun('opInformation')` to avoid name collisions through packages 1. `r citefun('opInformation')` verified and upgraded 1. R code - 34 exported functions, 6 internals 1. manual pages - 36 files 1. tests - 37 files, 450 tests 1. vignettes - 1 file 1. code as data - 39 files 1. Timing: tests 8s, checks 36s # Release 1.1.16 - January 2020 Main improvements are 1. Added methods `r citefun('verifyFunctionArguments')` to simplify input parameter type checks implementation # Release 1.1.15 Main improvements are 1. Added methods `r citefun('identifyOPInstrumentationLevel')`, `r citefun('retrievePackageFunctionNames')` 1. Upgraded `r citefun('packageFunctionsInformation')` 1. Added many new classes in `r citefun('sample-classes.R')` to ease demo and increase reuse 1. Updated vignettes 1. enforce package test coverage higher than 99%. # Release 1.1.14 Main improvements are 1. Added print methods for `r citefun('FunctionParameterName')`, `r citefun('EvaluationMode')` and `r citefun('TestCaseDefinition')` 2. solved issue on `r citefun('FunctionParameterTypeFactory')` when dealing with empty vectors as parameters 3. added new suffixes `r citechar('spi')`, `r citechar('sni')`, `r citechar('spr')`, `r citechar('snr')` 4. removed folders `r citefile('full-instrumetation')`, `r citefile('no-instrumentation')`, `r citefile('tc-defs')`, `r citefile('frt-defs')` from `r citefile('inst/code-samples')` # Release 1.1.10 Main improvements are 1. Added many tests to work with `r citechar('RC')`, `r citechar('S3')`, `r citechar('S4')`, `r citechar('R6')` classes 2. maintained higher code coverage higher than `r citefigure('99%')` # Release 1.1.9 Main improvements are 1. corrected many typographic errors in i/o with end-user 2. completed unit tests 3. enforced higher code coverage from `r citefigure('75%')` up to `r citefigure('99.28%')` 4. changed many functions visibility from hidden `r comment('internal to package')` to visible `r comment('end-user available')`. 5. completed documentation 6. cleaned up package dependencies.
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/inst/doc/release-notes.Rmd
citeit <- function(x_s) paste0('<cite class="itb">', x_s, '</cite>') citefun <- function(x_s) paste0('<cite class="it">', x_s, '</cite>') citeop <- function(x_s) paste0('<cite class="op">', x_s, '</cite>') citearg <- function(x_s) paste0('<cite class="os">', x_s, '</cite>') citeval <- function(x_s) paste0('<cite class="ea">', x_s, '</cite>') citesection <- function(x_s) paste0('<cite class="bj">', x_s, '</cite>') citecode <- function(x_s) paste0('<cite class="oc">', x_s, '</cite>') citechar <- function(x_s) paste0('<cite class="isa">', x_s, '</cite>') cmt <- function(x_s) paste0('<cite class="comment">', x_s, '</cite>') citefigure <- function(x_s) paste0('<cite class="figure">', x_s, '</cite>') citetime <- function(x_s) paste0('<cite class="time">', x_s, '</cite>') citefile <- function(x_s) paste0('<cite class="file">', x_s, '</cite>') citefolder <- function(x_s) paste0('<cite class="folder">', x_s, '</cite>') citeexec <- function(x_s) paste0('<cite class="exec">', x_s, '</cite>') citeEA <- function() { n <- 0 function(x_s) { n <<- n + 1 paste0('<cite class="oc"> EA#', n, ' ', x_s, '</cite>') } } cmt <- function(x_s) paste0('<cite class="comment">', x_s, '</cite>') rdoc <- citeval('wyz.code.rdoc') roxy <- citeval('roxygen2') op <- citeval('wyz.code.offensiveProgramming') R <- citeit('R') brkfun <- function(x_s) { paste(sapply(x_s, function(e) paste('\u25b6', e, '<br/>')), collapse = '') } showTable <- function(x_dt_1) { DT::datatable(x_dt_1, options = list(pageLength = 25)) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/vignettes/common-style.R
--- title: "wyz.code.offensiveProgramming releases" author: "Fabien GELINEAU" date: "last update on 2020-04-19" output: rmarkdown::html_vignette: css: style.css number_sections: true toc: false vignette: > %\VignetteIndexEntry{wyz.code.offensiveProgramming releases} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- <img src='images/op-hex.png' alt='offensive programming' style='width:30%'/> ```{r setup, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "") source('common-style.R') ``` # name [awesome-asterion-omega] package-version [1.1.24] timestamp [2023-09-25 08:27:33] 1. CRAN notes about Rd files requires adaptations 1. Changed `r citefile("retrieveTestCaseDefinitions.rd")` and `r citefile("retrieveFunctionReturnTypes.R")` # name [awesome-asterion-psi] package-version [1.1.23] timestamp [2021-10-05 22:58:54] 1. CRAN 3 notes 1. DESCRIPTION change URL - added an ending / as it seemed required 1. removed lazydata as there is no data folder 1. On :`r citefile("FunctionParameterTypeFactory.R")` conditionned example run. Kept only for unix systems. # name [awesome-asterion-khi] package-version [1.1.22] timestamp [2021-10-05 20:17:45] 1. CRAN information on obsolescence of lubridate - need to remove dependency. 1. lubridate::date() was used in file `r citefile("FunctionParameterTypeFactory.R")`. <pre> FunctionParameterTypeFactory.R: list('da' , 'date' , list(lubridate::is.Date) , type_classes$date), FunctionParameterTypeFactory.R: list('dc' , 'POSIXct' , list(lubridate::is.POSIXct) , type_classes$date), FunctionParameterTypeFactory.R: list('dl' , 'POSIXlt' , list(lubridate::is.POSIXlt) , type_classes$date), </pre> 1. Test, Duration: `r citefigure('7.7s')`, OK: `r citefigure('450')` 1. `r citeexec('R CMD check')`, Duration: `r citefigure('32.1s')`, 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 1. `r citeval('Commercial software release management')` 1. `r citefolder('vignette')` content update 1. `r citeop("git")` alignment # name [awesome-asterion-phi] package-version [1.1.21] timestamp [2020-11-09 19:57:38] 1. enforced R 4.0 1. Test, Duration: `r citefigure('7.3s')`, OK: `r citefigure('450')` 1. `r citeexec('R CMD check')`, Duration: `r citefigure('33.8s')`, 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 1. `r citeval('Commercial software release management')` 1. `r citefolder('vignette')` content update 1. `r citeop("git")` alignment # 1. modified implementation `r citefun("matchFunctionArguments")` function to solve aborption issue when called with empty parameter list. 1. modified `r citefun("FunctionParameterTypeFactory")` function. Added cantor real type. Latest release replaces fully older ones, that are now considered obsoletes. Keep the pace, and upgrade your packages to use the latest version! # Release awesome-asterion-tau - 1.1.19 - 2020-05-04 1. Test, Duration: `r citefigure('7.1s')`, OK: `r citefigure('450')` 1. `r citeexec('R CMD check')`, Duration: `r citefigure('33.8s')`, 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ 1. `r citeval('Commercial software release management')` 1. `r citefolder('vignette')` structure update 1. `r citefolder('vignette')` content update # Release 1.1.18 - awesome-asterion-sigma - 2005-05-04 Main improvements are 1. polished all `r citeit('R')` `r citefile('.Rd')` documentation files 1. R code - `r citefigure(34)` exported functions, `r citefigure(6)` internals 1. manual pages - `r citefigure(36)` files 1. tests - `r citefigure(36)` files 1. vignettes - `r citefigure(1)` files 1. code as data - `r citefigure(39)` files 1. Timing: tests 8s Duration: `r citefigure('7.2s')` for `r citefigure('450')` tests 1. R CMD check results ─ wyz.code.offensiveProgramming 1.1.18 ─ Duration: `r citefigure('37.1s')` - 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ # Release 1.1.17 Main improvements are 1. removed environment variable `r citecode("OP_TYPE_FACTORY")` management. Replaced by `r citecode("options('op_type_factory')")` 1. removed environment variable `r citecode("OP_AUDIT")` management. Replaced by `r citecode("options('op_audit')")` 1. removed default valued argument `r citecode("functionParameterTypeFactory_o_1 = retrieveFactory()")` from many functions, as it is useless and can be directly accessed/determined by the code. 1. Changed field `r citeop('function_name')` to `r citeop('name')` in `r citefun('packageFunctionsInformation')` for consistency reasons 1. `r citefun('packageFunctionsInformation')` renamed to `r citefun('opInformation')` to avoid name collisions through packages 1. `r citefun('opInformation')` verified and upgraded 1. R code - 34 exported functions, 6 internals 1. manual pages - 36 files 1. tests - 37 files, 450 tests 1. vignettes - 1 file 1. code as data - 39 files 1. Timing: tests 8s, checks 36s # Release 1.1.16 - January 2020 Main improvements are 1. Added methods `r citefun('verifyFunctionArguments')` to simplify input parameter type checks implementation # Release 1.1.15 Main improvements are 1. Added methods `r citefun('identifyOPInstrumentationLevel')`, `r citefun('retrievePackageFunctionNames')` 1. Upgraded `r citefun('packageFunctionsInformation')` 1. Added many new classes in `r citefun('sample-classes.R')` to ease demo and increase reuse 1. Updated vignettes 1. enforce package test coverage higher than 99%. # Release 1.1.14 Main improvements are 1. Added print methods for `r citefun('FunctionParameterName')`, `r citefun('EvaluationMode')` and `r citefun('TestCaseDefinition')` 2. solved issue on `r citefun('FunctionParameterTypeFactory')` when dealing with empty vectors as parameters 3. added new suffixes `r citechar('spi')`, `r citechar('sni')`, `r citechar('spr')`, `r citechar('snr')` 4. removed folders `r citefile('full-instrumetation')`, `r citefile('no-instrumentation')`, `r citefile('tc-defs')`, `r citefile('frt-defs')` from `r citefile('inst/code-samples')` # Release 1.1.10 Main improvements are 1. Added many tests to work with `r citechar('RC')`, `r citechar('S3')`, `r citechar('S4')`, `r citechar('R6')` classes 2. maintained higher code coverage higher than `r citefigure('99%')` # Release 1.1.9 Main improvements are 1. corrected many typographic errors in i/o with end-user 2. completed unit tests 3. enforced higher code coverage from `r citefigure('75%')` up to `r citefigure('99.28%')` 4. changed many functions visibility from hidden `r comment('internal to package')` to visible `r comment('end-user available')`. 5. completed documentation 6. cleaned up package dependencies.
/scratch/gouwar.j/cran-all/cranData/wyz.code.offensiveProgramming/vignettes/release-notes.Rmd
Colorizer <- function() { colorizeText <- function(colorFunction_f_1 = crayon::blue) { function(text_s) { unlist(lapply(text_s, colorFunction_f_1)) } } l <- lapply(list(crayon::red, crayon::yellow, crayon::green, crayon::blue, crayon::magenta), colorizeText) names(l) <- c('error', 'warning', 'message', 'info', 'other') l }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/Colorizer.R
GenerationContext <- function(targetFolder_s_1 = tempdir(), overwrite_b_1 = FALSE, verbosity_b_1 = FALSE, useMarkers_b_1 = FALSE) { self <- environment() class(self) <- append('GenerationContext', class(self)) if (!dir.exists(targetFolder_s_1)) stop(targetFolder_s_1, ' must be an existing folder') self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/GenerationContext.R
InputContext <- function(object_o_1, methodName_s_1 = NA_character_, packageName_s_1 = NA_character_, dataFilename_s_1 = NA_character_) { self <- environment() class(self) <- append('InputContext', class(self)) kinds <- c('package', 'class', 'method', 'function', 'data') kind <- if (is.na(dataFilename_s_1)) { if (is.null(object_o_1)) { ifelse(is.na(methodName_s_1), 1, 4) } else { ifelse(is.na(methodName_s_1), 2, 3) } } else 5 data_name <- if (kind == 5) removeFilenameExtension(basename(dataFilename_s_1)) else NULL file_name <- NA_character_ use_markers <- FALSE hack_description <- { value <- options('rdoc_hack')$rdoc_hack if (is.null(value)) FALSE else isTRUE(value) } setUseMarkers <- function(value_b_1) use_markers <<- value_b_1 number_replacements <- 0L markerGenerator <- function() { function() { number_replacements <<- number_replacements + 1 sprintf('XXX_%03d', number_replacements) } } generateConditionalMarkerGenerator <- function() { mg <- markerGenerator() function(force_b_1 = FALSE) { if (use_markers || force_b_1) mg() else NULL } } generateConditionalMarker <- generateConditionalMarkerGenerator() getKind <- function() kinds[kind] instrumentationLevel <- if (kind != 5) identifyOPInstrumentationLevel(object_o_1, methodName_s_1) class_kind <- if (is.null(object_o_1)) NA else getObjectClassKind(object_o_1) class_name <- if (is.null(object_o_1)) 'no-class' else getObjectClassNames(object_o_1)$classname beautifier <- beautify() retrieveStrategy <- function() { presence <- buildIdentityList(c("Won't", 'Could', 'Should', 'Must')) generation <- buildIdentityList(c('systematic', 'conditionned', 'none')) patch <- buildIdentityList(c('replace', 'add', 'none')) buildResult <- function(strategy_l) { dt <- data.table::rbindlist(strategy_l) data.table::setnames(dt, colnames(dt), c('section_name', 'section_presence', 'section_generation', 'patchable')) list(case = kinds[kind], strategy = dt) } if (kind == 5) { data_strategy <- list( list('name' , presence$MUST , generation$SYSTEMATIC , patch$NONE ), list('docType' , presence$MUST , generation$SYSTEMATIC , patch$NONE ), list('alias' , presence$MUST , generation$SYSTEMATIC , patch$ADD ), list('title' , presence$MUST , generation$SYSTEMATIC , patch$REPLACE), list('description' , presence$MUST , generation$SYSTEMATIC , patch$REPLACE), list('usage' , presence$MUST , generation$SYSTEMATIC , patch$NONE ), list('arguments' , presence$COULD , generation$CONDITIONNED, patch$REPLACE), list('details' , presence$SHOULD, generation$CONDITIONNED, patch$REPLACE), list('value' , presence$COULD , generation$SYSTEMATIC , patch$REPLACE), list('format' , presence$MUST , generation$NONE , patch$ADD ), list('source' , presence$MUST , generation$NONE , patch$ADD ), list('custom_section', presence$COULD , generation$NONE , patch$ADD ), list('references' , presence$COULD , generation$NONE , patch$ADD ), list('author' , presence$COULD , generation$CONDITIONNED, patch$REPLACE), list('note' , presence$COULD , generation$NONE , patch$ADD ), list('seealso' , presence$COULD , generation$NONE , patch$ADD ), list('examples' , presence$COULD , generation$SYSTEMATIC , patch$REPLACE), list('keyword' , presence$MUST , generation$SYSTEMATIC , patch$ADD ), list('concept' , presence$COULD , generation$NONE , patch$ADD ), list('encoding' , presence$SHOULD, generation$CONDITIONNED, patch$REPLACE), list('synopsis' , presence$COULD , generation$NONE , patch$ADD ), list('Rdversion' , presence$COULD , generation$NONE , patch$ADD ), list('RdOpts' , presence$COULD , generation$NONE , patch$ADD ), list('Sexpr' , presence$COULD , generation$NONE , patch$ADD ) ) return(buildResult(data_strategy)) } method_strategy <- list( list('name' , presence$MUST , generation$SYSTEMATIC , patch$NONE ), list('alias' , presence$MUST , generation$SYSTEMATIC , patch$ADD ), list('title' , presence$MUST , generation$SYSTEMATIC , patch$REPLACE), list('description' , presence$MUST , generation$SYSTEMATIC , patch$REPLACE), list('usage' , presence$MUST , generation$SYSTEMATIC , patch$NONE ), list('arguments' , presence$COULD , generation$CONDITIONNED, patch$REPLACE), list('details' , presence$SHOULD, generation$CONDITIONNED, patch$REPLACE), list('value' , presence$MUST , generation$SYSTEMATIC , patch$REPLACE), list('custom_section', presence$COULD , generation$NONE , patch$ADD ), list('references' , presence$COULD , generation$NONE , patch$ADD ), list('author' , presence$COULD , generation$CONDITIONNED, patch$REPLACE), list('note' , presence$COULD , generation$NONE , patch$ADD ), list('seealso' , presence$COULD , generation$NONE , patch$ADD ), list('examples' , presence$MUST , generation$SYSTEMATIC , patch$REPLACE), list('keyword' , presence$COULD , generation$NONE , patch$ADD ), list('concept' , presence$COULD , generation$NONE , patch$ADD ), list('encoding' , presence$SHOULD, generation$CONDITIONNED, patch$REPLACE), list('synopsis' , presence$COULD , generation$NONE , patch$ADD ), list('Rdversion' , presence$COULD , generation$NONE , patch$ADD ), list('RdOpts' , presence$COULD , generation$NONE , patch$ADD ), list('Sexpr' , presence$COULD , generation$NONE , patch$ADD ) ) if (kind %in% c(3, 4)) return(buildResult(method_strategy)) class_strategy <- append(method_strategy, list(list('docType', presence$MUST, generation$SYSTEMATIC, patch$NONE)), 1L) if (kind == 2) return(buildResult(class_strategy)) package_strategy <- class_strategy findIndex <- function(seekFor_s_1) { nex <- unlist(lapply(seq_len(length(package_strategy)), function(k) { if (package_strategy[[k]][[1]] == seekFor_s_1) k else 0 })) nex[nex != 0][1] } package_strategy[[findIndex('arguments')]] <- list('arguments', presence$COULD, generation$NONE, patch$ADD) package_strategy[[findIndex('value')]] <- list('value', presence$COULD, generation$NONE, patch$ADD) package_strategy[[findIndex('examples')]] <- list('examples', presence$COULD, generation$NONE, patch$ADD) buildResult(package_strategy) } buildMethodName <- function() { switch(class_kind, 'S3' = paste0(methodName_s_1, '.', class_name), 'S4' = paste0(class_name, '@', methodName_s_1), paste0(class_name, '$', methodName_s_1) ) } getName <- function() { switch(kind, packageName_s_1, class_name, methodName_s_1, methodName_s_1, data_name ) } produceName <- function() { switch(kind, paste0(packageName_s_1, '-package'), paste0(class_name, '-class'), paste0(class_name, '-', methodName_s_1), methodName_s_1, data_name ) } getFilename <- function() { if (is.na(file_name)) file_name <<- normalizeFilename(produceName()) file_name } produceDocType <- function() { switch(kind, 'package', 'class', NULL, NULL, 'data') } produceAlias <- function() { switch(kind, c(paste0(packageName_s_1, '-package'), packageName_s_1), c(paste0(class_name, '-class'), class_name), c(buildMethodName(), methodName_s_1), methodName_s_1, data_name ) } produceTitle <- function() { switch(kind, generateMarkup(packageName_s_1, 'packageTitle', inline_b_1 = TRUE), paste('Class', class_name), paste0('Method ', buildMethodName()), paste('Function', methodName_s_1), paste('Data set', data_name) ) } produceDescription <- function() { switch(kind, generateMarkup(packageName_s_1, 'packageDescription', inline_b_1 = TRUE), sentensize(paste(class_kind, 'class', class_name)), if (hack_description) { sentensize(paste('use this method to', generateLabel(methodName_s_1))) } else { if (!instrumentationLevel$offensive_programming) generateConditionalMarker() else { sentensize(paste('use this method to', generateLabel(methodName_s_1))) } }, if (hack_description || instrumentationLevel$semantic_naming) { sentensize(paste('use this function to', generateLabel(methodName_s_1))) } else generateConditionalMarker() ) } produceUsage <- function() { switch(kind, paste0('library(', packageName_s_1, ')'), getObjectSignature(object_o_1), getObjectMethodSignature(object_o_1, methodName_s_1), getFunctionSignature(methodName_s_1), data_name ) } produceArguments <- function() { transformEmptyness <- function(x_s) { if (is.null(x_s) || length(x_s) == 0) return(NULL) x_s } args <- switch(kind, NULL, { fn <- getObjectConstructor(object_o_1) if (!is.function(fn$function_f)) NULL else retrieveFunctionArgumentNames(fn$function_f) #fn <- tryCatch(get(class_name, mode = 'function'), error = NULL) #if (!is.function(fn)) NULL else retrieveFunctionArgumentNames(fn) # NULL }, transformEmptyness(getObjectFunctionArgumentNames(object_o_1)[[methodName_s_1]]), transformEmptyness(retrieveFunctionArgumentNames(methodName_s_1)), NULL ) if (is.null(args)) return(NULL) sapply(args, function(e) { fpn <- FunctionParameterName(e) generateMarkup(e ,'item', if (fpn$isSemanticName()) getTypeLabel(fpn) else generateConditionalMarker(TRUE), inline_b_1 = FALSE ) }, USE.NAMES = FALSE) } produceValue <- function() { switch(kind, NULL, sentensize(paste('an', beautifier$italicCode('object'), 'instance of', ifelse(is.na(class_kind), '', beautifier$italicCode(class_kind)), 'class', beautifier$enhanceCodeLink(class_name))), # ifelse(instrumentationLevel$offensive_programming, # 'OP instrumentation for method ... TBD XXX', # generateConditionalMarker()), # ifelse(instrumentationLevel$offensive_programming, # 'OP instrumentation for function... TBD XXX', # generateConditionalMarker()), generateConditionalMarker(), generateConditionalMarker(), NULL ) } produceDetails <- function() { switch(kind, c('The DESCRIPTION file', generateMarkup(packageName_s_1, 'packageDESCRIPTION', inline_b_1 = FALSE), generateMarkup(packageName_s_1, 'packageIndices', inline_b_1 = FALSE) ), generateConditionalMarker(), generateConditionalMarker(), generateConditionalMarker() ) } produceAuthor <- function() { p <- if (!is.na(packageName_s_1)) { c(generateMarkup(packageName_s_1, 'packageAuthor'), '', paste('Maintainer:', generateMarkup(packageName_s_1, 'packageMaintainer')) ) } else generateConditionalMarker() } produceKeyword <- function() { switch(kind, 'package', 'class', 'method', 'function', 'datasets') } produceCustom_section <- function() { produceSubsections <- function(data_l) { unlist(lapply(seq_len(length(data_l)), function(k) { generateMarkup(names(data_l)[k], 'subsection', data_l[[k]], inline_b_1 = FALSE) })) } if (kind %in% c(2, 3)) { op <- extractObjectOPInformation(object_o_1, ifelse(kind == 2, NA_character_, methodName_s_1)) l <- switch(getObjectClassKind(object_o_1), 'R6' = extractR6ObjectInformation(object_o_1), 'S4' = extractS4ObjectInformation(object_o_1), 'S3' = extractS3ObjectInformation(object_o_1), 'RC' = extractRCObjectInformation(object_o_1), 'environment' = extractEnvObjectInformation(object_o_1), NULL ) return(c(produceSubsections(l), produceSubsections(op))) } NULL } produceFormat <- function() { if (kind == 5) { d <- dim(object_o_1) dd <- paste0('dimension', ifelse(length(d) < 2, '', 's')) sentensize(paste(class_name, 'of', dd, paste0(d, collapse = 'x'))) } else { NULL } } produceSource <- function() { if (kind == 5) { generateConditionalMarker() } else { NULL } } produceReferences <- produceNote <- produceSeealso <- produceExamples <- produceConcept <- produceRdversion <- produceSynopsis <- produceSexpr <- produceRdOpts <- function() generateConditionalMarker() produceEncoding <- function() 'UTF-8' self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/InputContext.R
ManualPageBuilder <- function(inputContext_o_1, processingContext_o_1 = ProcessingContext(), generationContext_o_1 = GenerationContext()) { self <- environment() class(self) <- append('ManualPageBuilder', class(self)) strategy <- inputContext_o_1$retrieveStrategy() colorizer <- Colorizer() getStrategy <- function() strategy assembleManualPage <- function(pieces_l) { pieces <- pieces_l extraneous <- processingContext_o_1$extraneous_l post_processing <- processingContext_o_1$postProcessing_l special_sections <- c('name', 'alias', 'usage') standard_sections <- setdiff(strategy$strategy$section_name, 'custom_section') modifiable_sections <- setdiff(standard_sections, special_sections) multi_sections <- c('keyword', 'concept') patched <- modified <- vector('character', 128L) pi <- mi <- 1L # manage standard sections creations and replacements - MONO ss <- intersect(names(extraneous), setdiff(modifiable_sections, multi_sections)) sapply(ss, function(e) { if (generationContext_o_1$verbosity_b_1) cat('standard section mono', e, '\n') pieces[[e]] <<- extraneous[[e]] modified[mi] <<- e mi <<- mi + 1L }) # manage standard sections creations and replacements - MULTI ms <- intersect(names(extraneous), multi_sections) sapply(ms, function(e) { if (generationContext_o_1$verbosity_b_1) cat('standard section multi', e, '\n') pieces[[e]] <<- extraneous[[e]] modified[mi] <<- e mi <<- mi + 1L }) # manage custom sections creations cs <- setdiff(names(extraneous), modifiable_sections) sapply(cs, function(e) { if (generationContext_o_1$verbosity_b_1) cat('custom section', e, '\n') pieces[[e]] <<- extraneous[[e]] modified[mi] <<- e mi <<- mi + 1L }) # patch content patchable <- setdiff(names(pieces), special_sections) senv <- { value <- options('rdoc_classification')$rdoc_classification # must hold the package name if (is.null(value)) '' else if (is.character(value)) value else '' } if (senv != '') { ns <- tryCatch(getNamespace(senv), error = function(e) {NA}) # if (is.environment(ns)) { value_fun <- options('rdoc_function')$rdoc_function # must hold the inventory function name e.g. opRdocInformation value_fun <- if (is.null(value_fun)) '' else if (is.character(value_fun)) value else '' if (value_fun %in% getNamespaceExports(ns)) { m <- 'classification' if (!m %in% patchable) { km <- inputContext_o_1$getName() if (generationContext_o_1$verbosity_b_1) cat(m, km, '\n') pieces[[m]] <- extractClassificationInformation(km, senv) modified[mi] <- m mi <- mi + 1L } } } } patchable <- setdiff(names(pieces), special_sections) sapply(patchable, function(e) { if (exists(e, post_processing)) { if (generationContext_o_1$verbosity_b_1) cat('patch', e, '\n') pieces[[e]] <<- post_processing[[e]](pieces[[e]]) patched[pi] <<- e pi <<- pi + 1L } }) nm <- names(pieces) sl <- lapply(seq_len(length(pieces)), function(k) { if (is.null(pieces[[k]])) NULL else generateSection(nm[k], pieces[[k]]) }) list(pieces = Filter(Negate(is.null), sl), modifications = if (mi > 1L) modified[1:(mi - 1L)] else NA_character_, patches = if (pi > 1L) patched[1:(pi - 1L)] else NA_character_) } documentContent <- function() { sections <- setdiff(getStandardSectionNames(), strategy$section_name) modified <- vector('logical', length(sections)) pieces <- lapply(seq_len(length(sections)), function(k) { function_name <- paste0('produce', capitalize(sections[[k]])) fn <- inputContext_o_1[[function_name]] b <- is.function(fn) #cat(sections[[k]], 'function', function_name, 'does exist\n') rv <- if (b) fn() else NULL modified[k] <<- !is.null(rv) rv }) names(pieces) <- sections w <- which(names(pieces) == "custom_section") if (length(w) > 0) names(pieces)[w] <- 'Information' list(pieces = pieces, modifications = sections[modified]) } interpretResults <- function(result_l) { simplePluralize <- function(x_s, flag_b_1, suffix_s_1 = ':') { paste0(x_s, ifelse(flag_b_1, 's', ''), suffix_s_1) } if (!is.list(result_l)) abort('result_l must be a list') if (length(setdiff(c('logic', 'context'), names(result_l))) > 0) abort('result_l does not seem to be of right format') if (length(setdiff(c('filename', 'overwritten'), names(result_l$context))) > 0) abort('result_l does not seem to be of right format') generated <- extra_generated <- section_presence <- patched <- NULL # nse cat('filename is', result_l$context$filename, strBracket(ifelse(result_l$context$overwritten, 'OVERWRITTEN', 'UNTOUCHED')), '\n') gen <- result_l$logic[generated == TRUE | extra_generated == TRUE]$section_name lgen <- length(gen) if (lgen > 0) cat('generated', lgen, simplePluralize('section', lgen > 1), paste(colorizer$info(gen), collapse = ', '), '\n') pat <- result_l$logic[patched == TRUE]$section_name lpat <- length(pat) if (lpat > 0) cat('patched', lpat, simplePluralize('section', lpat > 1), paste(colorizer$info(pat), collapse = ', '), '\n') wrong <- result_l$logic[section_presence == 'MUST' & !(generated == TRUE | extra_generated == TRUE | patched == TRUE)]$section_name lwrong <- length(wrong) if (lwrong > 0) cat('missing', lwrong, simplePluralize('section', lwrong > 1), paste(colorizer$error(wrong), collapse = ', '), '\n') advice <- result_l$logic[section_presence == 'SHOULD' & !(generated == TRUE | extra_generated == TRUE | patched == TRUE)]$section_name ladvice <- length(advice) if (ladvice > 0) cat('probably missing', ladvice, simplePluralize('section', ladvice > 1), paste(colorizer$other(advice), collapse = ', '), '\n') if (inputContext_o_1$number_replacements > 0L) cat('replacements to manage:', colorizer$error(inputContext_o_1$number_replacements), '\n') } buildManualPage <- function() { if (generationContext_o_1$verbosity_b_1) cat("Creating manual page for", inputContext_o_1$getKind(), inputContext_o_1$getFilename(),'\n') inputContext_o_1$setUseMarkers(generationContext_o_1$useMarkers_b_1) pieces <- documentContent() content <- assembleManualPage(pieces$pieces) fb <- produceDocumentationFile(inputContext_o_1$getFilename(), paste(unlist(content$pieces), collapse = '\n'), generationContext_o_1) section_name <- section_presence <- extra_generated <- generated <- patched <- NULL # nse generation <- copy(strategy$strategy) generation[, `:=`(section_generation = NULL, patchable = NULL)] data.table::set(generation, NULL, 'generated', FALSE) data.table::set(generation, NULL, 'extra_generated', FALSE) data.table::set(generation, NULL, 'patched', FALSE) generation[section_name %in% pieces$modifications, `:=`(generated = TRUE)] generation[section_name %in% content$modifications, `:=`(extra_generated = TRUE)] generation[section_name %in% content$patches, `:=`(patched = TRUE)] generation[, `:=`(missing = (section_presence == 'MUST' & generated == FALSE)) ] invisible(list(logic = generation, context = fb)) } self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/ManualPageBuilder.R
ProcessingContext <- function(extraneous_l = list(), postProcessing_l = list()) { self <- environment() class(self) <- append('ProcessingContext', class(self)) verifyExtraneous <- function(extraneous_l) { if (is.list(extraneous_l)) return(TRUE) stop('extraneous_l must be a list') } verifyPostProcessing <- function(postProcessing_l) { if (is.list(postProcessing_l)) { if (all(sapply(postProcessing_l, wyz.code.offensiveProgramming::matchFunctionSignature, function(content_s){}))) return(TRUE) } stop('postProcessing_l must be a list of functions taking one argument named content_s') } verifyExtraneous(extraneous_l) verifyPostProcessing(postProcessing_l) self }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/ProcessingContext.R
auditDocumentationFiles <- function(folder_s_1m) { lf <- list.files(folder_s_1m, utils::glob2rx("*.Rd"), full.names = TRUE) w <- sapply(lf, function(e) { h <- computeDocumentationStatistics(e) f <- Filter(Negate(is.na), h$line_length_issue) if (length(f) > 0L) e else NA_character_ }) list( correct = names(Filter(is.na, w)), incorrect = names(Filter(Negate(is.na), w)) ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/auditDocumentationFiles.R
beautify <- function(escapeBraces_b_1 = FALSE) { generateFunction <- function(keyword_s_1) { function(entries_s) { sapply(entries_s, generateMarkup, keyword_s_1, escapeBraces_b_1 = escapeBraces_b_1, USE.NAMES = FALSE) } } candidates <- sort(c('acronym', 'bold', 'cite', 'dQuote', 'email', 'emph', 'enc', 'env', 'figure', 'file', 'format', 'kbd', 'link', 'option', 'pkg', 'preformatted', 'samp', 'source', 'sQuote', 'strong', 'verb', 'var', 'url', 'code')) l <- sapply(candidates, generateFunction) l$codeLink <- function(entries_s) l$code(l$link(entries_s)) l$enhanceCodeLink <- function(entries_s) l$emph(l$bold(l$code(l$link(entries_s)))) l$italicCode <- function(entries_s) l$emph(l$code(entries_s)) l$boldCode <- function(entries_s) l$bold(l$code(entries_s)) l$R <- function() { generateMarkup(keyword_s_1 = 'R')} l$ldots <- function() { generateMarkup(keyword_s_1 = 'ldots')} l$dots <- function() { generateMarkup(keyword_s_1 = 'dots')} l }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/beautify.R
completeManualPage <- function(filename_s_1, processingContext_o, add_b_1 = TRUE, verbosity_b_1 = FALSE) { sections <- getSectionContent(filename_s_1) ef <- function(x_s) { if (substr(x_s, 1, 1) == '\\') return(substring(x_s, 2L)) x_s } section_names <- sapply(sections, function(e) ef(e$name)) nm <- names(processingContext_o$postProcessing_l) if (length(nm) == 0L) return(FALSE) if (add_b_1) { lapply(nm, function(e) { if (verbosity_b_1) cat('adding', e, '\n') sections[[e]] <<- list(name = paste0('\\', e), content = processingContext_o$postProcessing_l[[e]](NULL)) }) } else { lapply(nm, function(e) { w <- which(section_names == e) if (length(w) == 1) { if (verbosity_b_1) cat('patching', e, w[1], '\n') sections[[w[1]]] <<- list( name = paste0('\\', e), content = processingContext_o$postProcessing_l[[e]](sections[[w[1]]]$content) ) } }) } section_names <- sapply(sections, function(e) ef(e$name)) content <- lapply(seq_len(length(sections)), function(k) { generateSection(section_names[k], sections[[k]]$content) }) fnc <- readLines(filename_s_1, warn = FALSE) writeLines(c(fnc, unlist(content)), con = filename_s_1) TRUE }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/completeManualPage.R
computeDocumentationStatistics <- function(filename_s_1, maxLineLength_pi_1 = 100L) { sections <- getSectionContent(filename_s_1) data.table::data.table( keywords = sapply(sections, function(e) regmatches(e$name, gregexpr('[a-zA-Z]+', e$name))), lines = sapply(sections, function(e) { l <- stringr::str_count(e$content, '\n') ifelse(l, l - 1L, 1L) }), line_length_issue = sapply(sections, function(e) { l <- strsplit(e$content, '\n')[[1]] n <- nchar(l) w <- which(n > maxLineLength_pi_1) if (length(w) == 0) NA_character_ else paste(w - 1L, collapse = ', ') }) ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/computeDocumentationStatistics.R
convertExamples <- function(examples_l, captureOutput_b_1n = TRUE, mode_s_1n = c(NA_character_, 'donttest', 'dontrun', 'dontshow')[1]) { generateExamples <- function(data_l, mode_s = NA_character_) { ld <- length(data_l) lm <- length(mode_s) b <- lm > 1 if (b) stopifnot(lm == ld) sd <- setdiff(unique(mode_s), c(NA_character_, 'donttest', 'dontrun', 'dontshow')) stopifnot(length(sd) == 0) unlist(lapply(seq_len(ld), function(k) { if (is.na(mode_s[ifelse(b, k, 1)])) { paste(generateMarkup(data_l[[k]], inline_b_1 = FALSE), '\n') } else { generateMarkup(data_l[[k]], mode_s[ifelse(b, k, 1)], inline_b_1 = FALSE) } })) } generateExamplesTrace <- function(examples_l, captureOutput_b_1n = TRUE) { if (!is.list(examples_l)) stop('examples_l must be a list of functions') b <- sapply(examples_l, wyz.code.offensiveProgramming::matchFunctionSignature) if (!all(b)) stop('examples_l must be a list of functions. Erroneous entries ', strBrace(which(b == FALSE))) s <- paste(rep('-', 7), collapse = '') len <- length(captureOutput_b_1n) lapply(seq_len(length(examples_l)), function(k) { b <- if (len == 1) captureOutput_b_1n else captureOutput_b_1n[k] v <- vector('character', 2L + ifelse(b, 1, 0)) v[1] <- paste('#', s, 'example', k, s) v[2] <- as.character(body(examples_l[[k]])[-1]) if (b) v[3] <- paste('#', paste0(examples_l[[k]](), collapse = ', ')) v }) } generateParagraph( generateExamples( generateExamplesTrace(examples_l, captureOutput_b_1n), mode_s_1n ) ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/convertExamples.R
documentationSymbols <- function() { list( black_right_triangle = '\\ifelse{latex}{\\out{$\\longmapsto$}}{\\ifelse{html}{\\out{&#x25B6;}}{\\\\u25b6}}', bulls_eye = '\\ifelse{latex}{\\out{$\\multimap$}}{\\ifelse{html}{\\out{&#x25CE;}}{\\\\u25ce}}', black_diamond = '\\ifelse{latex}{\\out{$\\mapsto$}}{\\ifelse{html}{\\out{&#x25C6;}}{\\\\u25c6}}', black_square = '\\ifelse{latex}{\\out{$\\rightarrow$}}{\\ifelse{html}{\\out{&#x25A0;}}{\\\\u25a0}}' ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/documentationSymbols.R
escapeContent <- function(content_s_1, escapeBraces_b_1 = FALSE) { patchArobas <- function(x_s) { if (stringr::str_count(x_s, '@') == 0L) return(x_s) paste(strsplit(x_s, "@@|@")[[1]], collapse = '@@', sep = '@@') } patchPercent <- function(x_s) { if (stringr::str_count(x_s, '%') == 0L) return(x_s) paste(strsplit(x_s, "\\\\%|%")[[1]], collapse = '\\%', sep = '\\%') } patchOB <- function(x_s) { if (stringr::str_count(x_s, '\\{') == 0L) return(x_s) paste(strsplit(x_s, "\\\\\\{|\\{")[[1]], collapse = '\\{', sep = '\\{') } patchCB <- function(x_s) { if (stringr::str_count(x_s, '\\}') == 0L) return(x_s) paste(strsplit(x_s, "\\\\\\}|\\}")[[1]], collapse = '\\}', sep = '\\}') } s <- paste0(content_s_1, '\t') # to circumvent strsplit final character issue s <- patchArobas(s) s <- patchPercent(s) if (!escapeBraces_b_1) return(substring(s, 1L, nchar(s) - 1L)) s <- patchOB(s) s <- patchCB(s) substring(s, 1L, nchar(s) - 1L) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/escapeContent.R
extractClassificationInformation <- function(name_s_1, packageName_s_1) { ns <- getNamespace(packageName_s_1) exported_symbols <- getNamespaceExports(ns) ff <- exported_symbols[grepl(glob2rx('op*Information'), exported_symbols)][1] fn <- tryCatch(get(ff, asNamespace(packageName_s_1)), error = function(e) NULL) if (!is.function(fn)) return(NULL) d <- fn() if (!data.table::is.data.table(d)) return(NULL) name <- NULL # nse info <- d[name == name_s_1] if (nrow(info) == 0) return(NULL) if (info$nature == 'INTERNAL') abort(name_s_1, 'is internal - Should not have manual page') black_right_triangle <- documentationSymbols()$black_right_triangle generateParagraph2NL( c( paste('STRATUM', black_right_triangle, info$stratum), paste('PHASING', black_right_triangle, info$phasing), paste('INTENT ', black_right_triangle, info$intent) ) ) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractClassificationInformation.R
extractEnvObjectInformation <- function(object_o_1) { on <- getObjectClassKind(object_o_1) stopifnot(on == 'environment') getPublicFields <- function() { l <- ls(object_o_1) f <- sapply(l, function(e) !typeof(object_o_1[[e]]) %in% c('closure')) generatePublicFieldParagraph(object_o_1, l[f]) } getPublicMethods <- function() { methods <- getObjectFunctionNames(object_o_1) if (is.null(methods) || length(methods) == 0) return(NULL) generatePublicMethodParagraph(object_o_1, methods) } l <- list( 'Environment fields' = getPublicFields(), 'Environment methods' = getPublicMethods() ) Filter(Negate(is.null), l) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractEnvObjectInformation.R
extractObjectOPInformation <- function(object_o_1, methodName_s_1 = NA_character_) { vos <- verifyObjectNames(object_o_1) class_name <- getObjectClassNames(object_o_1)$classname no_method <- is.na(methodName_s_1) beautifier <- beautify() testnums <- NA_integer_ function_name <- NULL #nse symbol <- documentationSymbols()$black_right_triangle getSemanticNaming <- function() { c( if (no_method) { sentensize(paste('class name compliance is', beautifier$italicCode(vos$class_name_compliance))) } else { w <- which(names(vos$function_name_compliance) == methodName_s_1) if (length(w) == 0) abort('unable to find function', methodName_s_1, 'from object of class', class_name) generateParagraph2NL(c( sentensize( paste('function name compliance is', beautifier$italicCode(vos$function_name_compliance[w])) ), sentensize( paste('function parameter-names compliance is', beautifier$italicCode(vos$parameter_name_compliance[function_name == methodName_s_1]$name_compliance_check) ) ), sentensize( paste('function parameter-names semantic naming compliance is', beautifier$italicCode(vos$parameter_name_compliance[function_name == methodName_s_1]$semantic_naming_check) ) ) ) ) } ) } getFunctionReturnTypes <- function() { frt <- retrieveFunctionReturnTypes(object_o_1) if (no_method) { c( sentensize( paste('class owns', if (vos$owns_function_return_type_information) { ifelse(vos$is_function_fully_instrumented, 'full', 'partial') } else { 'no' }, 'function return type instrumentation') ), if (data.table::is.data.table(frt)) { dk <- copy(frt) data.table::set(dk, NULL, 'function_name', beautifier$bold(dk$function_name)) data.table::setnames(dk, colnames(dk), beautifier$code(colnames(dk))) generateTable(dk, 'rr') } else NULL ) } else { paste(symbol, sentensize( paste('function return type is', if (data.table::is.data.table(frt)) { beautifier$bold( beautifier$code(frt[function_name == methodName_s_1]$return_value) ) } else { 'not instrumented' } ) ) ) } } getTestCaseDefinitions <- function() { rtc <- retrieveTestCaseDefinitions(object_o_1) if (is.data.table(rtc)) testnums <<- seq_len(nrow(rtc)) function_name <- NULL # nse if (no_method) { c( sentensize( paste('class owns', if (vos$owns_test_case_definitions) { ifelse(vos$is_test_case_fully_instrumented, 'full', 'partial') } else { 'no' }, 'test case definitions') ), if (data.table::is.data.table(rtc)) { dk <- rtc[, list(recorded_tests = .N), by = c('function_name')] data.table::set(dk, NULL, 'function_name', beautifier$bold(dk$function_name)) data.table::setnames(dk, colnames(dk), beautifier$code(colnames(dk))) generateTable(dk, 'rr') } else NULL ) } else { paste(symbol, sentensize( paste('Test case definition', if (data.table::is.data.table(rtc)) { paste('brings', beautifier$bold( beautifier$code(nrow(rtc[function_name == methodName_s_1])) ), 'cases' ) } else { 'is not instrumented' } ) ) ) } } getExamples <- function() { vn <- tolower( paste(unlist(regmatches(class_name, gregexpr('[A-Z]+', class_name))), collapse = '') ) ob <- paste(vn, '<-', getObjectSignature(object_o_1)) if (is.na(testnums[1])) return(ob) l <- length(testnums) if (l == 0) return(ob) # en <- environmentName(environment(tryCatch(get(class_name, mode = 'function'), # error = function(e) 'XXX_PKG' ))) n <- sample(testnums, 1) p <- c( 'library("data.table")', 'library("wyz.code.offensiveProgramming")', '', # paste0('source(findFilesInPackage("', class_name, '", "', # en, '")[1])'), # '', ob, paste('tcnum <-', n, paste0('# [1,', max(testnums), ']')), '', '# standard_R_evaluation mode', 'se <- EvaluationMode(defineEvaluationMode()[1])', paste0('ser <- runTestCase(', vn, ', tcnum , se)'), '', '# type_checking_enforcement mode', 'tc <- EvaluationMode(defineEvaluationMode()[3])', paste0('tcr <- runTestCase(', vn, ', tcnum, tc)') ) beautifier$preformatted(generateParagraph(p)) } l <- list( 'offensive programming - semantic naming' = getSemanticNaming(), 'offensive programming - function return types' = getFunctionReturnTypes(), 'offensive programming - test case definitions' = getTestCaseDefinitions(), 'offensive programming - examples' = getExamples() ) Filter(Negate(is.null), l) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractObjectOPInformation.R
extractR6ObjectInformation <- function(object_o_1) { on <- getObjectClassKind(object_o_1) stopifnot(on == 'R6') class_name <- getObjectClassNames(object_o_1)$classname generator <- eval(parse(text = class_name)) beautifier <- beautify() getDefinition <- function() { inh <- generator$get_inherit() lock_class <- generator$lock_class lock_objects <- generator$lock_objects portability <- generator$portable c( if (is.null(inh)) inh else sentensize(paste('Class', class_name, 'inherits from', inh)), sentensize('Lock class is', beautifier$code(lock_class)), sentensize('Lock objects is', beautifier$code(lock_objects)), sentensize('Class portability is', beautifier$code(portability)) ) } getPublicFields <- function() { fields <- generator$public_fields if (is.null(fields)) return(fields) generatePublicFieldParagraph(object_o_1, names(fields)) } getPublicMethods <- function() { methods <- getObjectFunctionNames(object_o_1) if (is.null(methods) || length(methods) == 0) return(NULL) generatePublicMethodParagraph(object_o_1, methods) } getActiveBindings <- function() { active_bindings <- generator$active if (is.null(active_bindings)) return(active_bindings) generateParagraphCR( paste(documentationSymbols()$bulls_eye, beautifier$bold(names(active_bindings))) ) } l <- list( 'R6 class definition' = getDefinition(), 'R6 public fields' = getPublicFields(), 'R6 public methods' = getPublicMethods(), 'R6 active bindings' = getActiveBindings() ) Filter(Negate(is.null), l) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractR6ObjectInformation.R
extractRCObjectInformation <- function(object_o_1) { on <- getObjectClassKind(object_o_1) stopifnot(on == 'RC') class_name <- getObjectClassNames(object_o_1)$classname getDefinition <- function() { inh <- selectSuperClasses(class_name) c( if (is.null(inh)) inh else sentensize(paste('Class', class_name, 'inherits from', inh)) ) } getFields <- function() { l <- ls(object_o_1) if (length(l) == 0) return(NULL) f <- sapply(l, function(e) !typeof(object_o_1[[e]]) %in% c('closure')) if (all(f == FALSE)) return(NULL) fields <- l[f] generatePublicFieldParagraph(object_o_1, fields) } getMethods <- function() { methods <- getObjectFunctionNames(object_o_1) if (is.null(methods) || length(methods) == 0) return(NULL) generatePublicMethodParagraph(object_o_1, methods) } l <- list( 'RC class definition' = getDefinition(), 'RC fields' = getFields(), 'RC methods' = getMethods() ) Filter(Negate(is.null), l) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractRCObjectInformation.R
extractS3ObjectInformation <- function(object_o_1) { on <- getObjectClassKind(object_o_1) stopifnot(on == 'S3') getFields <- function() { l <- ls(object_o_1) if (length(l) == 0) return(NULL) f <- sapply(l, function(e) !typeof(object_o_1[[e]]) %in% c('closure')) fields <- l[f] # if (is.null(fields) || length(fields) == 0) return(NULL) # self is mandatory field generatePublicFieldParagraph(object_o_1, fields) } getMethods <- function() { methods <- getObjectFunctionNames(object_o_1) if (is.null(methods) || length(methods) == 0) return(NULL) generatePublicMethodParagraph(object_o_1, methods) } l <- list( 'S3 fields' = getFields(), 'S3 methods' = getMethods() ) Filter(Negate(is.null), l) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractS3ObjectInformation.R
extractS4ObjectInformation <- function(object_o_1) { on <- getObjectClassKind(object_o_1) stopifnot(on == 'S4') class_name <- getObjectClassNames(object_o_1)$classname beautifier <- beautify() getDefinition <- function() { inh <- selectSuperClasses(class_name) c( if (is.null(inh)) inh else sentensize(paste('Class', class_name, 'inherits from', inh)) ) } getFields <- function() { fields <- slotNames(object_o_1) # slots can not be empty as it means pure virtual class #if (is.null(fields) || length(fields) == 0) return(NULL) generateParagraphCR( paste(documentationSymbols()$black_diamond, beautifier$bold(fields), sapply(fields, function(e) typeof(slot(object_o_1, e))) ) ) } getMethods <- function() { methods <- getObjectFunctionNames(object_o_1) if (is.null(methods) || length(methods) == 0) return(NULL) generatePublicMethodParagraph(object_o_1, methods) } l <- list( 'S4 class definition' = getDefinition(), 'S4 fields' = getFields(), 'S4 methods' = getMethods() ) Filter(Negate(is.null), l) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/extractS4ObjectInformation.R
generateEnc <- function(entries_l) { lapply(entries_l, function(e) generateMarkup(e$text, 'enc', e$ascii)) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateEnc.R
generateEnumeration <- function(entries_s, itemize_b_1 = FALSE) { if (length(entries_s) == 0) abort('cannot enumerate without entries') keyword <- ifelse(itemize_b_1, 'itemize', 'enumerate') s <- lapply(entries_s, function(e) paste('\\item ', e)) generateMarkup(generateParagraph(s), keyword) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateEnumeration.R
generateLabel <- function(identifier_s_1) { tolower(gsub('([A-Z]+)', ' \\1', identifier_s_1, perl = TRUE)) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateLabel.R
generateMarkup <- function(content_s, keyword_s_1 = NA_character_, content2_s = NA_character_, inline_b_1 = TRUE, useSpace_b_1 = FALSE, escapeBraces_b_1 = FALSE, content3_s = NA_character_) { generateKeyword <- function(keyword_s_1) paste0('\\', keyword_s_1) sep <- ifelse(inline_b_1, '', '\n') mergeString <- function(cnt_s) paste(cnt_s, collapse = sep) if (missing(content_s)) return(generateKeyword(keyword_s_1)) v <- escapeContent(mergeString(content_s), escapeBraces_b_1) if (is.na(keyword_s_1)) return(v) double_content <- !is.na(content2_s[1]) triple_content <- !is.na(content3_s[1]) if (triple_content && !double_content) abort('cannot set third content withoud second content') required_content <- list( double = c('href', 'enc', 'method', 'S3method', 'S4method', 'item', 'tabular', 'section', 'subsection', 'if', 'newcommand', 'renewcommand', 'deqn', 'eqn'), triple = c('ifelse') ) if (double_content) { se <- paste0(generateKeyword(keyword_s_1), '{') if (!triple_content) { if (!keyword_s_1 %in% required_content$double) abort('unautorized keyword double content', keyword_s_1) sp <- ifelse(keyword_s_1 %in% c('section', 'subsection'), '\n', '') rv <- paste0(se, v, '}', ifelse(useSpace_b_1, ' ', ''), '{', sp, escapeContent(mergeString(content2_s), escapeBraces_b_1), sp, '}' ) return(rv) } else { if (!keyword_s_1 %in% required_content$triple) abort('unautorized keyword triple content', keyword_s_1) return(paste0(se, v, '}{', escapeContent(mergeString(content2_s), escapeBraces_b_1), '}{', escapeContent(mergeString(content3_s), escapeBraces_b_1), '}')) } } if (!keyword_s_1 %in% union(setdiff(rdocKeywords(), unlist(required_content)), 'href')) abort('unknown keyword', keyword_s_1) se <- paste0(generateKeyword(keyword_s_1), '{', sep) mergeString(paste0(se, v, sep, '}')) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateMarkup.R
generateOptionSexpr <- function(options_s_1, topicName_s_1, escapeBraces_b_1 = FALSE) { paste0('\\Sexpr[', options_s_1, ']{', escapeContent(topicName_s_1, escapeBraces_b_1), '}') } generateOptionLink <- function(options_s_1, topicName_s_1, escapeBraces_b_1 = FALSE) { paste0('\\link[', options_s_1, ']{', escapeContent(topicName_s_1, escapeBraces_b_1), '}') } producePackageLink <- function(packageName_s_1, topicName_s_1) { pn <- paste0(packageName_s_1, ':', topicName_s_1) generateOptionLink(pn, pn) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateOptionLink.R
generateParagraph <- function(..., collapse_s_1 = '\n', addFinalSeparator_b_1 = FALSE) { p <- paste(..., sep = collapse_s_1, collapse = collapse_s_1) if (addFinalSeparator_b_1) paste0(p, collapse_s_1) else p } generateParagraphCR <- function(..., addFinalSeparator_b_1 = FALSE) { generateParagraph(..., collapse_s_1 = '\\cr\n', addFinalSeparator_b_1 = addFinalSeparator_b_1) } generateParagraph2NL <- function(..., addFinalSeparator_b_1 = FALSE) { generateParagraph(..., collapse_s_1 = '\n\n', addFinalSeparator_b_1 = addFinalSeparator_b_1) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateParagraph.R
generatePublicFieldParagraph <- function(object_o_1, fields_s) { dt <- data.table::data.table( ' ' = documentationSymbols()$black_diamond, field = beautify()$bold(fields_s), type = sapply(fields_s, function(e) typeof(object_o_1[[e]]))) generateTable(dt, showHeader_b_1 = FALSE) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generatePublicFieldParagraph.R
generatePublicMethodParagraph <- function(object_o_1, methods_s) { beautifier <- beautify() sig <- sapply(methods_s, function(e) { s <- getObjectMethodSignature(object_o_1, e) r <- regexpr('(', s, fixed = TRUE) paste0(beautifier$bold(substr(s, 1, r[1] - 1)), beautifier$code(substring(s, r[1]))) }) paste('\\cr', generateParagraphCR(paste(documentationSymbols()$black_square, sig))) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generatePublicMethodParagraph.R
generateReference <- function(data_l) { sentensize(paste('Refer to', generateMarkup(data_l$url, 'href', data_l$label), ifelse('comment' %in% names(data_l), data_l$comment, ''))) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateReference.R
generateS3MethodSignature <- function(methodName_s_1, className_s_1, argumentNames_s) { args <- if (length(argumentNames_s) == 0) '' else paste(argumentNames_s, collapse = ', ') paste0('\\method{', methodName_s_1, '}{', className_s_1, '}(', args, ')') }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateS3MethodSignature.R
generateSection <- function(sectionName_s_1, content_s) { rd <- rdocKeywords(TRUE) if (sectionName_s_1 %in% c( 'alias', rd$indices)) return(sapply(content_s, function(e) { generateMarkup(e, sectionName_s_1, inline_b_1 = TRUE) }, USE.NAMES = FALSE)) inl <- sectionName_s_1 %in% c('name', 'title', 'docType', 'encoding') if (sectionName_s_1 %in% c(rd$documentingFunctions, rd$documentingDataSets)) return(generateMarkup(content_s, sectionName_s_1, inline_b_1 = inl)) generateMarkup(paste0(toupper(substr(sectionName_s_1, 1L, 1L)), substring(sectionName_s_1, 2L)), 'section', content_s, inline_b_1 = FALSE) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateSection.R
generateTable <- function(content_dt, alignement_s_1 = NA_character_, numberRows_b_1 = FALSE, showHeader_b_1 = TRUE) { nc <- ncol(content_dt) if (nc == 0) abort('cannot build table without columns') nr <- nrow(content_dt) if (nr == 0) abort('cannot build table without rows') al <- if (is.na(alignement_s_1)) paste(rep('l', nc), collapse = '') else tolower(alignement_s_1) ss <- strsplit(al, '')[[1]] if (length(ss) != nc) abort(al, 'is length', length(ss), 'is wrong. Should be', nc) v <- setdiff(unique(ss), c('l', 'r', 'c')) if (length(v) > 0) abort(al, 'is a wrong alignement specification. Use only l, c and r, please.') if (numberRows_b_1) al <- paste0('r', al) header <- if (showHeader_b_1) paste0(paste(colnames(content_dt), collapse = ' \\tab '), '\\cr\n') else '' w <- sapply(seq_len(nr), function(k) { s <- sapply(seq_len(nc), function(j) { paste0(ifelse(k == 1 && j == 1, '\n', ''), ifelse(numberRows_b_1 && j == 1, paste0(k, ' \\tab '), ''), as.character(content_dt[k, j, with = FALSE])) }) paste(generateParagraph(s, collapse_s_1 = ' \\tab '), '\\cr\n') }) generateMarkup(al, 'tabular', c(header, w)) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/generateTable.R
getFunctionSignature <- function(functionName_s_1) { f <- tryCatch(get(functionName_s_1, mode = 'function'), error = function(e) NULL) if (is.null(f)) abort('no function', functionName_s_1, 'found') fo <- retrieveFunctionArguments(f) ag <- sapply(seq_len(length(fo)), function(k) { p <- manageSingleStrings(fo[[k]]) paste0(names(fo[k]), if (length(p) == 0) '' else if (nchar(p) > 0) paste(' =', p) else '') }, simplify = FALSE) paste0(functionName_s_1, strParenthesis(strJoin(normalizeSpaces(ag), ', '))) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/getFunctionSignature.R
getObjectConstructor <- function(object_o_1) { on <- wyz.code.offensiveProgramming::getObjectClassKind(object_o_1) if (is.na(on[1]) || on[1] == 'unknown') return(NA) cn <- getObjectClassNames(object_o_1) fn <- guardExecution({get(cn$classname)}) b <- TRUE if (on == 'R6') { b <- is.function(object_o_1$initialize) fn <- if (b) object_o_1$initialize else fn$new } if (!is.function(fn)) abort('unable to retrieve object signature for object', strBracket(cn$classname), strBracket(strJoin(cn$classnames))) list(function_f = fn, signature_flag = !b, on = on, classname = cn$classname) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/getObjectConstructor.R
getObjectMethodSignature <- function(object_o_1, methodName_s_1) { if (!is.object(object_o_1)) abort('parameter named object_o_1 is not an object') v <- getObjectClassKind(object_o_1) supported <- c('environment', 'S3', 'R6', 'S4', 'RC') if (!v %in% supported) abort(paste('parameter object_o_1 is not of supported type', strBracket(v), 'supported types are', strBracket(strJoin(supported)))) cn <- getObjectClassNames(object_o_1)$classname fn <- switch(v, 'S4' = selectMethod(methodName_s_1, cn), 'S3' = get(paste0(methodName_s_1, ".", cn)), 'RC' = object_o_1$getRefClass()$def@refMethods[[methodName_s_1]], object_o_1[[methodName_s_1]] ) if (!is.function(fn)) abort(paste('method', methodName_s_1, 'does not exist in provided', v, 'object of class', cn)) fo <- retrieveFunctionArguments(fn) ag <- sapply(seq_len(length(fo)), function(k) { paste0(names(fo[k]), ifelse(is.symbol(fo[[k]]), '', paste(' =', manageSingleStrings(fo[[k]])))) }, simplify = FALSE ) args <- strParenthesis(strJoin(normalizeSpaces(ag), ', ')) # 'name' is a formal generic function; S3 methods will not likely be found ==> suppressWarnings # if (suppressWarnings(isS3method(f = methodName_s_1, class = cn))) { # generateS3MethodSignature(methodName_s_1, cn, args) # } else # WARNING: File /tmp/rdoc/Bu_S3-class.Rd # checkRd: (7) /tmp/rdoc/Bu_S3-class.Rd:23: Tag \method not valid outside a code block paste0(methodName_s_1, args) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/getObjectMethodSignature.R
getObjectSignature <- function(object_o_1) { goc <- getObjectConstructor(object_o_1) if (is.na(goc[1])) return(NA) fo <- retrieveFunctionArguments(goc$function_f) ag <- sapply(seq_len(length(fo)), function(k) { paste0(names(fo[k]), ifelse(is.symbol(fo[[k]]), '', paste(' =', manageSingleStrings(fo[[k]])))) }, simplify = FALSE ) args <- if (goc$on == 'R6' && !goc$signature) '()' else strParenthesis(strJoin(normalizeSpaces(ag), ', ')) paste0(paste0(goc$classname, ifelse(goc$on == 'R6', '$new', '')), args) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/getObjectSignature.R
getSectionContent <- function(filename_s_1) { if (!file.exists(filename_s_1)) abort(filename_s_1, 'does not exist') l <- readLines(filename_s_1, warn = FALSE) s <- paste(l, collapse = '\n') p <- strsplit(s, '')[[1]] start <- 1L nob <- ncb <- 0L sections <- vector('list', length(l)) sk <- 1L section_name <- '' sapply(seq_len(length(p)), function(k) { if (p[k] == '{') { if (nob == 0) { section_name <<- stringr::str_trim(paste(p[start:(k - 1L)], collapse = '')) start <<- k + 1L } nob <<- nob + 1 } if (p[k] == '}') ncb <<- ncb + 1 if (nob == ncb && nob != 0) { sections[[sk]] <<- list(name = section_name, content = paste(p[start:(k - 1L)], collapse = '')) sk <<- sk + 1L start <<- k + 1L nob <<- 0L ncb <<- 0L } }) if (sk == 1L) return(list()) data <- sections[1:(sk - 1L)] id <- sapply(data, function(e) e$name == '\\section') w <- which(id == TRUE) sapply(rev(w), function(k) { data[[k]]$name <<- data[[k]]$content data[[k]]$content <<- data[[k + 1]]$content data[[k + 1]] <<- NULL }) Filter(Negate(is.null), data) }
/scratch/gouwar.j/cran-all/cranData/wyz.code.rdoc/R/getSectionContent.R