Re: [R] Unexpected input in function

2012-03-20 Thread Schryver, Jack C.
Thank you for your responses. You helped me to see something right in front of 
me that I should have noticed quickly. I copy/pasted my script from MS Word 
instead of using a safer text editor. I did catch the funky double-quotes the 
MS Word uses, but I think it also sometimes substitutes a dash for a minus sign.

Jack

-Original Message-
From: ted@deb [mailto:ted@deb] On Behalf Of Ted Harding
Sent: Monday, March 19, 2012 4:56 PM
To: r-help@r-project.org
Cc: Schryver, Jack C.; Schryver, Jack C.; Sarah Goslee
Subject: Re: [R] Unexpected input in function

I think the most likely explanation is that something in
the input string has had the effect of inserting an invisible
"character" between the "-" and the "a" in "b-a", and a
possible suspect is pollution by UTF8: see the discussion at

http://r.789695.n4.nabble.com/unexpected-input-in-rpart-td3168363.html

Or a character "copy&paste"d from an editor that uses a
non-ASCII encoding for its characters. See e.g.:

http://support.rstudio.org/help/discussions/problems/
386-error-unexpected-input-in

and:

http://www.mail-archive.com/r-help@r-project.org/msg71798.html


On 19-Mar-2012 Sarah Goslee wrote:
> I think you'll need to provide a reproducible example, because your
> code works for me:
> 
>> fsubt <- function(a) {
> + b <- 1:length(a)
> + b-a
> + }
>>
>>
>> fsubt(1:5)
> [1] 0 0 0 0 0
>>
>> fsubt(sample(1:10))
>  [1] -8 -6  1  1 -1  5  3  1  4  0
>>
>> fsubt(2)
> [1] -1
> 
> 
> On Mon, Mar 19, 2012 at 4:01 PM, Schryver, Jack C. 
> wrote:
>> Hi,
>>
>> Although the following statements work individually in R, they produce an
>> error if placed inside a function as below:
>>
>> fsubt <- function(a) {
>> b <- 1:length(a)
>> b-a
>> }
>>
>> The error message is:
>>
>> Error: unexpected input in:
>> "b <- 1:length(a)
>> b-"
>>
>> Any insight would be greatly appreciated.
>>
>> Thanks,
>> Jack
> 
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org

-
E-Mail: (Ted Harding) 
Date: 19-Mar-2012  Time: 20:56:04
This message was sent by XFMail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Unexpected input in function

2012-03-19 Thread Ted Harding
I think the most likely explanation is that something in
the input string has had the effect of inserting an invisible
"character" between the "-" and the "a" in "b-a", and a
possible suspect is pollution by UTF8: see the discussion at

http://r.789695.n4.nabble.com/unexpected-input-in-rpart-td3168363.html

Or a character "copy&paste"d from an editor that uses a
non-ASCII encoding for its characters. See e.g.:

http://support.rstudio.org/help/discussions/problems/
386-error-unexpected-input-in

and:

http://www.mail-archive.com/r-help@r-project.org/msg71798.html


On 19-Mar-2012 Sarah Goslee wrote:
> I think you'll need to provide a reproducible example, because your
> code works for me:
> 
>> fsubt <- function(a) {
> + b <- 1:length(a)
> + b-a
> + }
>>
>>
>> fsubt(1:5)
> [1] 0 0 0 0 0
>>
>> fsubt(sample(1:10))
>  [1] -8 -6  1  1 -1  5  3  1  4  0
>>
>> fsubt(2)
> [1] -1
> 
> 
> On Mon, Mar 19, 2012 at 4:01 PM, Schryver, Jack C. 
> wrote:
>> Hi,
>>
>> Although the following statements work individually in R, they produce an
>> error if placed inside a function as below:
>>
>> fsubt <- function(a) {
>> b <- 1:length(a)
>> b-a
>> }
>>
>> The error message is:
>>
>> Error: unexpected input in:
>> "b <- 1:length(a)
>> b-"
>>
>> Any insight would be greatly appreciated.
>>
>> Thanks,
>> Jack
> 
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org

-
E-Mail: (Ted Harding) 
Date: 19-Mar-2012  Time: 20:56:04
This message was sent by XFMail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Unexpected input in function

2012-03-19 Thread R. Michael Weylandt
The OP's error suggests (to me) that there's a line break error
somewhere so it may be a funny quirk of encoding/OS incompatibility if
it's from a source()'d script.

Incidentally, the OP could also write the body of his function as a
one liner with:

seq_along(a) - a

Michael

On Mon, Mar 19, 2012 at 4:33 PM, Sarah Goslee  wrote:
> I think you'll need to provide a reproducible example, because your
> code works for me:
>
>> fsubt <- function(a) {
> + b <- 1:length(a)
> + b-a
> + }
>>
>>
>> fsubt(1:5)
> [1] 0 0 0 0 0
>>
>> fsubt(sample(1:10))
>  [1] -8 -6  1  1 -1  5  3  1  4  0
>>
>> fsubt(2)
> [1] -1
>
>
> On Mon, Mar 19, 2012 at 4:01 PM, Schryver, Jack C.  
> wrote:
>> Hi,
>>
>> Although the following statements work individually in R, they produce an 
>> error if placed inside a function as below:
>>
>> fsubt <- function(a) {
>> b <- 1:length(a)
>> b-a
>> }
>>
>> The error message is:
>>
>> Error: unexpected input in:
>> "b <- 1:length(a)
>> b-"
>>
>> Any insight would be greatly appreciated.
>>
>> Thanks,
>> Jack
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Unexpected input in function

2012-03-19 Thread Sarah Goslee
I think you'll need to provide a reproducible example, because your
code works for me:

> fsubt <- function(a) {
+ b <- 1:length(a)
+ b-a
+ }
>
>
> fsubt(1:5)
[1] 0 0 0 0 0
>
> fsubt(sample(1:10))
 [1] -8 -6  1  1 -1  5  3  1  4  0
>
> fsubt(2)
[1] -1


On Mon, Mar 19, 2012 at 4:01 PM, Schryver, Jack C.  wrote:
> Hi,
>
> Although the following statements work individually in R, they produce an 
> error if placed inside a function as below:
>
> fsubt <- function(a) {
> b <- 1:length(a)
> b-a
> }
>
> The error message is:
>
> Error: unexpected input in:
> "b <- 1:length(a)
> b-"
>
> Any insight would be greatly appreciated.
>
> Thanks,
> Jack

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Unexpected input in function

2012-03-19 Thread Schryver, Jack C.
Hi,

Although the following statements work individually in R, they produce an error 
if placed inside a function as below:

fsubt <- function(a) {
b <- 1:length(a)
b-a
}

The error message is:

Error: unexpected input in:
"b <- 1:length(a)
b-"

Any insight would be greatly appreciated.

Thanks,
Jack

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.