Discussion:
[R] "unexpected numeric constant" while reading tab delimited csv file
madr
2010-11-22 08:29:03 UTC
Permalink
my csv file is very simple - just one line for purpose of this test:
0{TAB}0

and read function is this:
csvdata = read.csv(file="d:/s/test.csv",head=FALSE,sep="\t")

then error comes:

Error in source("d:/test.csv") :
d:/test.csv:1:9: unexpected numeric constant
1: 0 0


but when I change delimiter to ; (colon) then error not shows up anymore
--
View this message in context: http://r.789695.n4.nabble.com/unexpected-numeric-constant-while-reading-tab-delimited-csv-file-tp3053252p3053252.html
Sent from the R help mailing list archive at Nabble.com.
madr
2010-11-22 09:06:22 UTC
Permalink
the problem shows up only in console when script is loaded thru source() and
separator character is eighter tab or space, strangely, when I'm running
script directly form file in text environment everything is ok.

[I'm reposing this because my previous post didn't get on the list because
double quote character at the beginning of a subject was eaten up when Re:
was added, now everything should be ok ]]
--
View this message in context: http://r.789695.n4.nabble.com/unexpected-numeric-constant-while-reading-tab-delimited-csv-file-tp3053252p3053291.html
Sent from the R help mailing list archive at Nabble.com.
Jeff Newmiller
2010-11-22 09:57:54 UTC
Permalink
madr wrote:
> my csv file is very simple - just one line for purpose of this test:
> 0{TAB}0
>
> and read function is this:
> csvdata = read.csv(file="d:/s/test.csv",head=FALSE,sep="\t")
>
> then error comes:
>
> Error in source("d:/test.csv") :
> d:/test.csv:1:9: unexpected numeric constant
> 1: 0 0
>
>
> but when I change delimiter to ; (colon) then error not shows up anymore
>
You seem to be referencing two different files somehow... one in the
root directory of your drive D, and the other in a subdirectory D:/s.
This may have something to do with it... or may be extraneous.

You haven't indicated what your working environment is, though the OS
seems likely to be some variant of Windows. In your other email, you
mention a distinction between whatever this environment is (RGui?) and
"console". Are you using Cygwin? could end-of-line termination (CRLF vs
LF) be causing you difficulty?

Perhaps you should follow the posting guide instructions...
madr
2010-11-22 10:17:36 UTC
Permalink
The folder are the same, I just deleted the long path because it is
irrelevant and by mistake left /s i one of the paths, they should be
identical.

I'm running this package:
http://cran.r-project.org/bin/windows/base/R-2.12.0-win.exe on win xp 32 bit
--
View this message in context: http://r.789695.n4.nabble.com/unexpected-numeric-constant-while-reading-tab-delimited-csv-file-tp3053252p3053370.html
Sent from the R help mailing list archive at Nabble.com.
Mike Marchywka
2010-11-22 11:29:34 UTC
Permalink
----------------------------------------
> Date: Mon, 22 Nov 2010 01:57:54 -0800
> From: jdnewmil at dcn.davis.ca.us
> To: madrazel at interia.pl
> CC: r-help at r-project.org
> Subject: Re: [R] "unexpected numeric constant" while reading tab delimited csv file
>
> madr wrote:
> > my csv file is very simple - just one line for purpose of this test:
> > 0{TAB}0
> >
> > and read function is this:
> > csvdata = read.csv(file="d:/s/test.csv",head=FALSE,sep="\t")
> >
> > then error comes:
> >
> > Error in source("d:/test.csv") :
> > d:/test.csv:1:9: unexpected numeric constant
> > 1: 0 0
> >
> >
> > but when I change delimiter to ; (colon) then error not shows up anymore
> >
> You seem to be referencing two different files somehow... one in the
> root directory of your drive D, and the other in a subdirectory D:/s.
> This may have something to do with it... or may be extraneous.
>
> You haven't indicated what your working environment is, though the OS

> mention a distinction between whatever this environment is (RGui?) and
> "console". Are you using Cygwin? could end-of-line termination (CRLF vs
> LF) be causing you difficulty?

The OP explained that and if you believe OP changing intended file changes
the error message. And, yes, I would strongly suggest getting cygwin
so you have some tools other than posting incomplete information of calling
tech support LOL. In this case, you would use something like "od" to verify
that your file is as you expect. Just as printing numerical data often
truncated digits, unprintable chars don't always show up on printing.
od -ax or something may be informative. Changing the tab may have caused
editor to change line endings or something else. Smart editors often
mess stuff up.



>
> Perhaps you should follow the posting guide instructions...
>
> ______________________________________________
> R-help at 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.
Duncan Murdoch
2010-11-22 11:38:52 UTC
Permalink
madr wrote:
> my csv file is very simple - just one line for purpose of this test:
> 0{TAB}0
>
> and read function is this:
> csvdata = read.csv(file="d:/s/test.csv",head=FALSE,sep="\t")
>
> then error comes:
>
> Error in source("d:/test.csv") :
> d:/test.csv:1:9: unexpected numeric constant
> 1: 0 0
>
>
> but when I change delimiter to ; (colon) then error not shows up anymore

You used source, not read.csv. They aren't the same thing.

If you typed what you said you typed, then you've hidden the real
read.csv function behind your own, and your own calls source. But I
don't think you typed what you said you typed.

Duncan Murdoch
Loading...