Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swirl package, #9 Functions Error #445

Closed
tgsutterby opened this issue Apr 5, 2016 · 12 comments
Closed

Swirl package, #9 Functions Error #445

tgsutterby opened this issue Apr 5, 2016 · 12 comments

Comments

@tgsutterby
Copy link

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

@seankross
Copy link
Member

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.

@tgsutterby
Copy link
Author

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.

@seankross
Copy link
Member

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

@tgsutterby
Copy link
Author

[1] "internal"

@seankross
Copy link
Member

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

@tgsutterby
Copy link
Author

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)
}
<environment: 0x0000000009495ac8>

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

@seankross
Copy link
Member

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

@ccoat
Copy link

ccoat commented Apr 20, 2016

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.

@seankross
Copy link
Member

See #434
On Wed, Apr 20, 2016 at 12:15 PM ccoat notifications@github.com 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
#445 (comment)

@ccoat
Copy link

ccoat commented Apr 20, 2016

Awesome, thanks @seankross!

@sbriones
Copy link

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."

@liefleh
Copy link

liefleh commented Apr 15, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants