Note that there are some explanatory texts on larger screens.

plurals
  1. POR 2.15.2 Error in source - unexpected '}' - trying to submit homework project
    primarykey
    data
    text
    <p>I am currently doing R class on Coursera, and the tasks is asking to write a specific function, save code to a file named getmonitor.R and run test script to evaluate the result.</p> <p>I been able to write the function and it seems to perform according to expectations in terms of input/output. But when I am trying to execute the test script. I am getting the following error message: </p> <pre><code>Error in source("getmonitor.R", local = TRUE) : getmonitor.R:11:1: unexpected '}' 10: } 11: } ^ In addition: Warning messages: 1: In grepl("\n", lines, fixed = TRUE) : input string 19 is invalid in this locale 2: In grepl("\n", lines, fixed = TRUE) : input string 20 is invalid in this locale </code></pre> <p>I tried was asking on the coursera community, but could not get an answer, also there I cannot really post my code. I am hoping I could find some help here. Below I'll provide the steps to reproduce.</p> <p>Function which needs to be created is defined as follows: "Write a function named 'getmonitor' that takes three arguments: 'id', 'directory', and 'summarize'. Given a monitor ID number, 'getmonitor' reads that monitor's particulate matter data from the directory specified in the 'directory' argument and returns a data frame containing that monitor's data. If 'summarize = TRUE', then 'getmonitor' produces a summary of the data frame with the 'summary' function and prints it to the console."</p> <p>Here is my solution to that:</p> <pre><code>&gt; getmonitor &lt;- function(id, directory, summarize = FALSE) { + filename &lt;- paste("/Users/siarhei/desktop/",directory,"/",sprintf("%03s", as.character(id)),".csv", sep="") + data &lt;- read.csv(filename) + if (summarize == TRUE) { + print(summary(data)) + } + } </code></pre> <p>If I run getmonitor(1,'specdata',TRUE), I am getting expected output.</p> <p>And then run command <code>save(getmonitor, file="getmonitor.R")</code> to save file to my wd according to course instructions. After that I run the test script, which is:</p> <pre><code>source("http://spark-public.s3.amazonaws.com/compdata/scripts/getmonitor-test.R") getmonitor.testscript() </code></pre> <p>What is supposed to happen here is that R would generate 2 output files, which I can submit online. However all I could get so far is an error above. Since the function is working properly, it seems like it's just some error in reading the file, but I could not figure that out. </p> <p>Would be really grateful for any tips here. If there's any chance to go online to figure that out in chat or hangout, I'd be extremely cool and helpful!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload