Swirl: Swirl package, #9 Functions Error

Created on 5 Apr 2016  ·  12Comments  ·  Source: swirldev/swirl

I am trying to run lesson #9 in swirl, called Functions. The lesson asks that you create a function using the code below, then submit that code using submit(). I type the code correctly, but when I use the submit() function a # is somehow inserted before the x (within my saved code). As the code with #x is not correct, I am unable to complete the assignment for Coursera.

boring_function <- function(x) {
x
}

R Studio 0.99.893 (3.2.3)
Windows 10 Home 64 bit

Most helpful comment

Hi @sbriones,

I had the same issue... when I re-read the exercise it says

Make sure to save your script before you type submit()."

Swirl automatically generate a script for me, but if it doesn't. You can just copy...

boring_function - function(x) {
x
}
submit()

...Into the upper part of R. Then go to file, save or save as, and save your script as boring_function.

For me it then worked, hopefully for you too.

All 12 comments

Try the following:

  1. Exit the lesson by using bye().
  2. Close all open R script editing windows.
  3. Close R or RStudio.
  4. Open R or RStudio.
  5. Restart the lesson.

If this doesn't solve your issue please let me know.

I tried that, it didn't work. I also tried running the command "options(editor = "internal")" before starting swirl and that didn't work either. Since none of that worked, I uninstalled and reinstalled R Studio thinking that maybe I had done something that caused it, and it still doesn't work.

@tgsutterby what do you get as the result of options()$editor?

[1] "internal"

If you restart RStudio what do you get as the result of options()$editor? Also what do you get as the result of sessionInfo()?

This is what I get from options()$editor, as soon as I open R Studio... Doesn't seem quite right. Maybe a problem with my editor?

function (name, file, title)
{
if (is.null(name) || is.function(name)) {
if (is.null(name)) {
if (!is.null(file) && nzchar(file))
targetFile <- file
else targetFile <- scratchFile
}
else {
functionSrc <- .rs.deparseFunction(name, TRUE, FALSE)
targetFile <- scratchFile
writeLines(functionSrc, targetFile)
}
if (.Call("rs_editFile", targetFile)) {
newFunc <- try(eval.parent(parse(targetFile)), silent = TRUE)
if (inherits(newFunc, "try-error")) {
stop(newFunc, "You can attempt to correct the error using ",
title, " = edit()")
}
return(newFunc)
}
else {
stop("Error occurred while editing function '", name,
"'")
}
}
else edit(name, file, title, editor = defaultEditor)
}

And this is what I get from sessionInfo()

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] tools_3.2.3

Also what version of swirl are you using? You can check this with packageVersion("swirl").

I am having issues with the R Programming Functions lesson as well. After successfully using the mean() function, I am prompted to modify a script but I seem to be missing information after that.

> mean(c(2, 4, 5))
[1] 3.666667

| You are doing so well!

  |=============                                                                                                                   |  10%

| Functions usually take arguments which are variables that the function operates on. For example, the mean() function takes a vector as
| an argument, like in the case of mean(c(2,6,8)). The mean() function then adds up all of the numbers in the vector and divides that sum
| by the length of the vector.

...

  |================                                                                                                                |  12%

| In the following question you will be asked to modify a script that will appear as soon as you move on from this question. When you
| have finished modifying the script, save your changes to the script and type submit() and the script will be evaluated. There will be
| some comments in the script that opens up, so be sure to read them!

...

  |==================                                                                                                              |  14%

| The last R expression to be evaluated in a function will become the return value of that function. We want this function to take one
| argument, x, and return x without modifying it. Delete the pound sign so that x is returned without any modification. Make sure to save
| your script before you type submit().

Error in editor(file = file, title = title) : 
  argument "name" is missing, with no default

| Leaving swirl now. Type swirl() to resume.
`

I have exited swirl (bye()), closed all open R script editing windows, restarted RStudio, and restarted the lesson.

See #434
On Wed, Apr 20, 2016 at 12:15 PM ccoat [email protected] wrote:

I am having issues with the R Programming Functions lesson as well. After
successfully using the mean() function, I am prompted to modify a script
but I seem to be missing information after that.

mean(c(2, 4, 5))
[1] 3.666667

| You are doing so well!

|============= | 10%

| Functions usually take arguments which are variables that the function operates on. For example, the mean() function takes a vector as
| an argument, like in the case of mean(c(2,6,8)). The mean() function then adds up all of the numbers in the vector and divides that sum
| by the length of the vector.

...

|================ | 12%

| In the following question you will be asked to modify a script that will appear as soon as you move on from this question. When you
| have finished modifying the script, save your changes to the script and type submit() and the script will be evaluated. There will be
| some comments in the script that opens up, so be sure to read them!

...

|================== | 14%

| The last R expression to be evaluated in a function will become the return value of that function. We want this function to take one
| argument, x, and return x without modifying it. Delete the pound sign so that x is returned without any modification. Make sure to save
| your script before you type submit().

Error in editor(file = file, title = title) :
argument "name" is missing, with no default

| Leaving swirl now. Type swirl() to resume.
`

I have exited swirl (bye()), closed all open R script editing windows,
restarted RStudio, and restarted the lesson.


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
https://github.com/swirldev/swirl/issues/445#issuecomment-212496251

Awesome, thanks @seankross!

I am having the same problem, tried the solutions, but couldn´t make it work.
I its always:
"The last R expression to be evaluated in a function will become the return value of
| that function. We want this function to take one argument, x, and return x without
| modifying it. Delete the pound sign so that x is returned without any modification.
| Make sure to save your script before you type submit().

boring_function <- function(x) {

  • x
  • }
    submit()

| Sourcing your script...

| That's not exactly what I'm looking for. Try again.

| Make sure to delete the pound sign so the last expression in the function is just x."

Hi @sbriones,

I had the same issue... when I re-read the exercise it says

Make sure to save your script before you type submit()."

Swirl automatically generate a script for me, but if it doesn't. You can just copy...

boring_function - function(x) {
x
}
submit()

...Into the upper part of R. Then go to file, save or save as, and save your script as boring_function.

For me it then worked, hopefully for you too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahaisiddharth picture sahaisiddharth  ·  49Comments

aquaal picture aquaal  ·  4Comments

darsp picture darsp  ·  6Comments

tklebel picture tklebel  ·  14Comments

sugarcane29 picture sugarcane29  ·  14Comments