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 errors out in the Functions module #434

Closed
sahaisiddharth opened this issue Mar 25, 2016 · 49 comments
Closed

swirl errors out in the Functions module #434

sahaisiddharth opened this issue Mar 25, 2016 · 49 comments
Labels

Comments

@sahaisiddharth
Copy link

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.

@seankross
Copy link
Member

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 notifications@github.com
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
#434

@guiml
Copy link

guiml commented Mar 25, 2016

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?

@sahaisiddharth
Copy link
Author

i am also using RStudio in Windows 10 64b.

@bkkesseler
Copy link

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.

@seankross
Copy link
Member

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

@bkkesseler
Copy link

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)
}

@sahaisiddharth
Copy link
Author

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

@seankross
Copy link
Member

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

@seankross
Copy link
Member

Hello all,

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

@sacooper74
Copy link

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

@sahaisiddharth
Copy link
Author

Thanks @seankross , it works fine now.

@brokawq
Copy link

brokawq commented Mar 31, 2016

This works for me as well!

Thank you

@ljr1984
Copy link

ljr1984 commented Apr 5, 2016

This works for me too!!
Thanks~

@zlf15197
Copy link

zlf15197 commented Apr 8, 2016

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

@seankross
Copy link
Member

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

@sidnair79
Copy link

thanks. this solution works

@Wrosinski
Copy link

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

@datageek2709
Copy link

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?

@ishgupta
Copy link

ishgupta commented Jun 5, 2016

Hello,

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

Thanks!

@inthse
Copy link

inthse commented Jun 17, 2016

Thanks, this worked for me.

@gauravbansal20nov
Copy link

@seankross Thx, really appreciated. I am able to see the script now... 👍

@kislay95
Copy link

@seankross That Really Helped.
Thank you

@sudhakarb
Copy link

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()
}
<environment: namespace:swirl>
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.

@kapilparashar
Copy link

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.

@seankross
Copy link
Member

@kapilparashar can you send a screenshot instead?

@kapilparashar
Copy link

Please find below screenshot.

[image: Inline image 2]

On Mon, Jul 11, 2016 at 9:20 AM, Sean Kross notifications@github.com
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
#434 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ATYyN8KYDGLVqR2JXA_q4x6OVx4zRBAfks5qUlEkgaJpZM4H4ll4
.

@seankross
Copy link
Member

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

@kapilparashar
Copy link

image

@seankross
Copy link
Member

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

@kapilparashar
Copy link

@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

@seankross
Copy link
Member

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

@kapilparashar
Copy link

kapilparashar commented Jul 11, 2016

Yes, below script is visible

image

@seankross
Copy link
Member

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

@kapilparashar
Copy link

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

@prem92
Copy link

prem92 commented Jan 12, 2017

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

@seankross
Copy link
Member

@prem92 Please read the question above for the answer.

@annie-mac
Copy link

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

@annie-mac
Copy link

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

@akaEmma
Copy link

akaEmma commented Apr 24, 2018

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

@RexGalilae
Copy link

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

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

No branches or pull requests