swirl errors out in the Functions module

Created on 25 Mar 2016  Â·  49Comments  Â·  Source: swirldev/swirl

Hi

When I go through the functions module as soon as it reaches a certain stage it exits swirl with the following error:

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

notable

Most helpful comment

Hello all,

Before you start swirl in RStudio, try entering options(editor = "internal"). Please let me know if that improves your situation.

All 49 comments

Are you using R with the RGui, with RStudio, in the terminal, or through
some other method?
On Fri, Mar 25, 2016 at 2:42 AM sahaisiddharth [email protected]
wrote:

Hi

When I go through the functions module as soon as it reaches a certain
stage it exits swirl with the following error:

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

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/swirldev/swirl/issues/434

I have a similar issue in the Getting and Cleaning Data when I reach the following step:

`
| Let's take it a step further. I just opened an R script for
| you that contains a partially constructed call to
| summarize(). Follow the instructions in the script
| comments.
|
| When you are ready to move on, save the script and type
| submit(), or type reset() to reset the script to its
| original state.

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

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

I use RStudio in Windows 10 64b

*_Version 0.99.892 *_– © 2009-2016 RStudio, Inc.
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) rstudio Safari/538.1 Qt/5.4.1

It appears to have something related to a fail when trying to open a file in my local RStudio...

Does anyone have a light on this?

i am also using RStudio in Windows 10 64b.

I am receiving the same error, with R 3.2.4 and RStudio 0.99.893 Windows 10 64b.

Ah! Found a workaround. Load R directly, not RStudio, and it will work fine. I'm just going to run this lesson in R, then jump back to RStudio after.

What do all of you get as a result of getOption("editor")?

getOption("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)
}

following is the result:

getOption("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)
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)
}

Thanks, I'll get to the bottom of this.

Hello all,

Before you start swirl in RStudio, try entering options(editor = "internal"). Please let me know if that improves your situation.

hey seankross - that works for me, the script now opens in R Editor... i'm on Version 0.99.893 – © 2009-2016 RStudio, Inc.

cheers, steve

Thanks @seankross , it works fine now.

This works for me as well!

Thank you

This works for me too!!
Thanks~

thanks,@seankross,it also works for me !
but i am wondering why it couldn't appear in the source windows as before?

@zlf15197 I'm working on it. It has to do with the new version of RStudio so it wasn't a change I could anticipate well.

thanks. this solution works

Had the same problem, worked for me too.
Thanks!

I just had the same problem and your solution worked for me as well. Thanks @seankross

Thanks!

Thanks, worked for me as well

sean kross~ Thank you. Your advice helps me get through the problem!!!

This works for me as well

hi,

I also have the same problem. i tried all the solution given. but still it remains same .

Please help me

thank you sean kross x

the solution worked fine for me, many thanks...
also, you don't have to restart swirl to make the change...

  • use play() to pause swirl
  • then use the options(editor = "internal") command given by seankross
  • then resume swirl with nxt()

solution worked! thanks!

Thanks a lot @seankross ! The solution works like a charm and I can now open the editor in rStudio.

Just out of curiosity, what might have been at the root of this problem?

Hello,

It worked for me too! but could anyone please comment on how does the command actually function?

Thanks!

Thanks, this worked for me.

@seankross Thx, really appreciated. I am able to see the script now... :+1:

@seankross That Really Helped.
Thank you

I am having a similar probelm... Please help!
What shall I call you? sudh

| Would you like to continue with one of these lessons?

1: R Programming Functions
2: No. Let me start something new.

Selection: 1

| 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().

myfunc <- function(x) {x}
myfunc(2)
[1] 2
submit
function ()
{
invisible()
}

submit()

| Sourcing your script...

| Not quite, but you're learning! Try again.

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

Hi every one
I am getting same problem after using the instruction given above by Mr. Seankros.
Please suggest

options(editor = "internal")
library(swirl)

| Hi! I see that you have some variables saved in your workspace. To keep
| things running smoothly, I recommend you clean up before starting swirl.

| Type ls() to see a list of the variables in your workspace. Then, type
| rm(list=ls()) to clear your workspace.

| Type swirl() when you are ready to begin.

ls()
[1] "a" "b" "bar" "baz"
[5] "boring_function" "c" "cnames" "con"
[9] "count" "d1" "d2" "data1"
[13] "data2" "data3" "dt" "f"
[17] "flags" "i" "ints" "k"
[21] "m" "mean" "my_char" "my_data"
[25] "my_div" "my_matrix" "my_matrix2" "my_mean"
[29] "my_na" "my_name" "my_seq" "my_sqrt"
[33] "my_vector" "new.y" "num_vect" "ok"
[37] "old.dir" "patients" "r" "remainder"
[41] "t1" "t2" "t3" "t4"
[45] "tf" "uncle" "USArrest" "USArrests"
[49] "val" "vec2" "vect" "vect2"
[53] "viewinfo" "x" "xx" "y"
[57] "z"
rm(list=ls())
swirl()

| Welcome to swirl! Please sign in. If you've been here before, use the same
| name as you did then. If you are new, call yourself something unique.

What shall I call you? kapil

| Would you like to continue with one of these lessons?

1: R Programming Dates and Times
2: R Programming Functions
3: No. Let me start something new.

Selection: 3

| Please choose a course, or type 0 to exit swirl.

1: R Programming
2: Take me to the swirl course repository!

Selection: 1

| Please choose a lesson, or type 0 to return to course menu.

1: Basic Building Blocks 2: Workspace and Files
3: Sequences of Numbers 4: Vectors
5: Missing Values 6: Subsetting Vectors
7: Matrices and Data Frames 8: Logic
9: Functions 10: lapply and sapply
11: vapply and tapply 12: Looking at Data
13: Simulation 14: Dates and Times
15: Base Graphics

Selection: 9

|
| | 0%

| Functions are one of the fundamental building blocks of the R language. They
| are small pieces of reusable code that can be treated like any other R
| object.

...

|
|= | 2%
| If you've worked through any other part of this course, you've probably used
| some functions already. Functions are usually characterized by the name of
| the function followed by parentheses.

...

|
|=== | 4%
| Let's try using a few basic functions just for fun. The Sys.Date() function returns a string representing today's date. Type Sys.Date() below and see what happens.

Sys.Date()
[1] "2016-07-11"

| You're the best!

|
|==== | 6%
| Most functions in R return a value. Functions like Sys.Date() return a value based on your computer's environment, while other functions manipulate input data in
| order to compute a return value.

...

|
|====== | 8%
| The mean() function takes a vector of numbers as input, and returns the average of all of the numbers in the input vector. Inputs to functions are often called
| arguments. Providing arguments to a function is also sometimes called passing arguments to that function. Arguments you want to pass to a function go inside the
| function's parentheses. Try passing the argument c(2, 4, 5) to the mean() function.

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

| Keep working like that and you'll get there!

|
|======= | 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().

x
Error: object 'x' not found

You're about to write your first function! Just like you would assign a value

to a variable with the assignment operator, you assign functions in the following

way:

#

function_name <- function(arg1, arg2){

Manipulate arguments in some way

Return a value

}

#

The "variable name" you assign will become the name of your function. arg1 and

arg2 represent the arguments of your function. You can manipulate the arguments

you specify within the function. After sourcing the function, you can use the

function by typing:

function_name(value1, value2)

#

Below we will create a function called boring_function. This function takes

the argument x as input, and returns the value of x without modifying it.

Delete the pound sign in front of the x to make the function work! Be sure to

save this script and type submit() in the console after you make your changes.

boring_function <- function(x) {

  • x
  • }
    submit()

| Sourcing your script...

| Not quite! Try again.

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

@kapilparashar can you send a screenshot instead?

Please find below screenshot.

[image: Inline image 2]

On Mon, Jul 11, 2016 at 9:20 AM, Sean Kross [email protected]
wrote:

@kapilparashar https://github.com/kapilparashar can you send a
screenshot instead?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/swirldev/swirl/issues/434#issuecomment-231748522, or mute
the thread
https://github.com/notifications/unsubscribe/ATYyN8KYDGLVqR2JXA_q4x6OVx4zRBAfks5qUlEkgaJpZM4H4ll4
.

@kapilparashar Can you please post the image directly to GitHub? I can't see it.

image

@kapilparashar It looks like the script editor isn't opening for you. You might have better luck using swirl within RStudio. Also make sure that you have the latest version of swirl installed.

@sahaisiddharth Seankross
I updated the swirl for recent version using this http://swirlstats.com/faq.html

install.packages("devtools")
library(devtools)
install_github("swirldev/swirl")
library(swirl)
swirl()
also tried swirl with Rstudio but result not effected

image

@kapilparashar is there a script hiding in the RStudio source window?

Yes, below script is visible

image

@kapilparashar save the script after changing it, and then enter submit() into the R console. I recommend you totally close and re-open RStudio before you attempt this.

Thanks a lot for your guidance. Please suggest how can i do same for (R x64 3.3.1). Means what problem there.I am new for this but enjoying whatever.

image

I am getting an error in functions course in swirl package.can any one pls help me on this.
I am using R studio 3.3.1
Thanks in advance.

| Sourcing your script...

| Not quite, but you're learning! Try again.

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

funct_error

@prem92 Please read the question above for the answer.

Looks like Rstudio needs swirl commands like submit entered prefaced with swirl:: so typing swirl::submit() submits the code

oops sorry, didn't recognise submit() because I hadn't loaded using library(swirl) first

The solution of typing "options(editor = "internal")" worked for me only after restarting R.

Using R Studio 1.1.456 and it doesn't work for me even after restarting

Was this page helpful?
0 / 5 - 0 ratings

Related issues

diadema378 picture diadema378  Â·  15Comments

aquaal picture aquaal  Â·  4Comments

bwkeim picture bwkeim  Â·  46Comments

seankross picture seankross  Â·  3Comments

JuanAndresAlban picture JuanAndresAlban  Â·  6Comments