-1

OK, simplifying it:

lat0 <- 42.61527
X <- 0.2023649
Z <- -0.9793102

Why does this give an error:

X <- X*cos(lat0) − Z*sin(-lat0)
## Error: unexpected input in "X <- X*cos(lat0) �"

and this doesn't?

X <- X*cos(42.61527) - Z*sin(-42.61527)

Here is the platform and R version:

platform       x86_64-w64-mingw32
version.string R version 3.0.2 (2013-09-25)

I'm trying to implement this method

Community
  • 1
  • 1
Rodrigo
  • 4,706
  • 6
  • 51
  • 94
  • It looks like an esoteric error related to something strange in your R session or workspace. Can you reproduce it in a clean R session? (And your example is not reproducible. It gives error on first line: cannot find function readOGR. I know you gave a link but it is better to copy all relevant parts e.g library (xyz) etc) – lebatsnok May 26 '14 at 18:52
  • I can't try your example without a definition of `Z` – Matthew Lundberg May 26 '14 at 18:53
  • Please give us a reproducible example http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – EDi May 26 '14 at 18:55
  • Sorry. I added the library(rgdal) and the definition of Z in the first part. Thank you! I'll try in a clean R session. – Rodrigo May 26 '14 at 18:55
  • Look the comments below. It looks like the R Console translate the hex string e2 88 92 into a minus sign... thank you all! – Rodrigo May 26 '14 at 19:04
  • @Rodrigo I edited your question to remove the original code, add the error message that I get from your example, and try to give a better title. Feel free to roll back or edit further, as you wish. – Matthew Lundberg May 26 '14 at 19:12
  • That's not the error I was getting. So I think we can delete this question...? – Rodrigo May 26 '14 at 19:22

1 Answers1

5

The thing that looks like a minus sign between X*cos(lat0) and Z*sin(-lat0), is not a minus sign:

X <- X*cos(lat0) − Z*sin(-lat0)

Here is a hex dump of this text:

0000000  sp   X  sp   <   -  sp   X   *   c   o   s   (   l   a   t   0
         20  58  20  3c  2d  20  58  2a  63  6f  73  28  6c  61  74  30
0000020   )  sp   b  bs dc2  sp   Z   *   s   i   n   (   -   l   a   t
         29  20  e2  88  92  20  5a  2a  73  69  6e  28  2d  6c  61  74
0000040   0   )  nl
         30  29  0a
0000043

What should be a - sign is the unicode character represented by the hex string e2 88 92

Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
  • Very strange. If I select all the X*cos(lat0) − Z*sin(-lat0) and run the selection, it gives me the 1 as result. If I run the whole line including the X <- , it crashes again. And it crashes only in the script window, not in the R Console... – Rodrigo May 26 '14 at 19:01
  • Note that in the lines with a problem, the hyphen is longer than a normal minus sign: `-` vs `−` – Matthew Lundberg May 26 '14 at 19:03
  • Yes, it is. Strange that the R Console made the substitution automatically... Thank you! – Rodrigo May 26 '14 at 19:04
  • @MatthewLundberg: Actually, THAT was a minus sign, a sign resulting from HTML `−` entity. :) – CiaPan May 31 '14 at 20:03
  • Sorry everybody (especially Rodrigo!), when responding in that thread I used HTML `−` instead of ASCII dash, because the minus is the same width as standard plus character. I had no idea it will cause some problem when copied-and-pasted as an expression to the R interpreter. – CiaPan Jun 01 '14 at 14:52