Sakhri Houssem
Sakhri Houssem

Reputation: 1063

Error in source() unexpected numeric constant

when I write an R script in a test.R file

nb <- 22

paste("Etudions le nombre: ",nb)
paste("Le logarithme népérien de ce nombre est: ", log(nb))
paste("La racine carrée de ce nombre est: ", sqrt(nb))
paste("Le cosinus de ce nombre est: ", cos(nb))
paste("Si on ajoute 3 au nombre ", nb, " on obtient: ", nb + 3)

q("ask")

I executed using :

source("/Users/shous/Desktop/Master2.0/LanguageR/test.R")

error message :

Error in source("/Users/shous/Desktop/Master2.0/LanguageR/test.R") :
/Users/shous/Desktop/Master2.0/LanguageR/test.R:1:9: unexpected numeric constant
1: nb <- 22

Upvotes: 0

Views: 3117

Answers (2)

Gregor Thomas
Gregor Thomas

Reputation: 145775

unexpected numeric constant 1: nb <- 22

This is R telling you that it found the line

nb <- 22

and that isn't valid syntax. You can duplicate this simply on the command line with something like a = a 22, which also isn't valid syntax. You need to correct that line of code - I don't know what you want it to be, perhaps there is a missing line break, or perhaps it should be  + 22 or Â[22], etc...

The line that produces the error does not occur in the code you show, perhaps you should make sure you are running the right file.

Upvotes: 0

franiis
franiis

Reputation: 1376

It can be encoding problem: unexpected numeric constant 1: nb <- 22

I guess you don't want to have this character Â.Try to change file encoding or rewrite problematic line (not copy paste).

Upvotes: 1

Related Questions