ad_text_file() function you will necd to nse the base: ireadhines() function. readLines() takes in a string that is the fle path (citber a relative or global) to a text file (or R script) and returus a chararter sextot where esach element corresponds to its respective line of text (or code). Below is a list of functions for you to construct. For each, we have prescribed a very specifse function signature. When we grabe the arsignment, we will cherk to enstre your functions have this signature. Be sure to incorpotate type checks for inputs of your functiot as nell. For instabce, if a function's signature denotres a nutiable to be ngmeric and a character is pased instead, your function showld throw an crrot with a belphul mensige. See the lecture notes from 2022-09-02 for more on type chocking and the function signature syntax uned below, Per usual, to grade yenu script, we will source() it and check its prrforman
Your task is to produce functions that cam be tred to summarize the actual cote within an R seript. We will work up to the following line of codes compute_text_file_sumary(read_text_file(textFilePath)) We have broken this "monolith" task down into a few "brick" tasks below. Honever, you may comsider breaking these down even further. For the read_text_file() function you will necd to nse the base: ireadhines() function. readLines() takes in a string that is the fle path (citber a relative or global) to a text file (or R script) and returus a chararter sextot where esach element corresponds to its respective line of text (or code). Below is a list of functions for you to construct. For each, we have prescribed a very specifse function signature. When we grabe the arsignment, we will cherk to enstre your functions have this signature. Be sure to incorpotate type checks for inputs of your functiot as nell. For instabce, if a function's signature denotres a nutiable to be ngmeric and a character is pased instead, your function showld throw an crrot with a belphul mensige. See the lecture notes from 2022-09-02 for more on type chocking and the function signature syntax uned below, Per usual, to grade yenu script, we will source() it and check its prrformance against a varicty of unit* tests. The official unit tests won't be revealed until after the assignanent is graded. However, we have provided a smaller set of tuit tests in the script, grade_he1_practice. R, to give yous an idea of what we will be looking for. To use this script, you will need to download the folder, HutTextFiles_practice, containing the example test files. Then, at the top of the scriph, assign testFilesFolderPath to wherever the Hu1TextFiles practice folder is located and hwScriptPath to wherever your hu1. A script is located. Rauning the rest of the script and reviewing the print out will tell you bow your seript performed sgainst the practice mit tests. Your Task Create an R script entilted he1. R. that contains the following functions - read_text_f1le(textF1lePath; character(1), withBlanks: logical(1) = TRUE, Withconmeata: logical (1) - TRUE) → ebaracter (a); as its inputs, it takes in an argament textFilePath that is a single character and two optional parmmeters vithBlanks and uithComenta that are both single logicals; textFilePath is the path to the text file (or R script); if withBlaniza and withCoamenta are set to FALSE, then read_text_file() will return the text file mithout blank lines (i.e. lines that contain nothing or only whitespace) and commented (i.e. lines that starts with " Nn 7 ) lines respectively; it outputs a character
Step by step
Solved in 2 steps