Error in source() unexpected numeric constant - r

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

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

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.

Related

Unexpected Coding Error on Arduino Uno R3

When I run this code it gives me an error, I am still a beginner so I don't know how to fix it.
This is what I have written so far
Giving a look in your code, you missed to place some semicolons (;) at the end of some instructions, to be more specific you miss them in lines:
5
32
34
37
40
In line 9, you have to type "Serial.begin(9600);" instead "serial.begin(9600);"
On the last else, you forgot to enclose the instructions between "{}" and placing the '}' to close the void loop.
You are making reference to a routine named getVoltage, but I don't see it
Another issue that I can see is that you have to write with uppercase words like: OUTPUT, INPUT, HIGH and LOW
Please share more details once you be able to fix this observations

Unexpected input error when doing subtraction in R

i try to run:
x = (1 / 1 – 2)
And here is the message:
Error: unexpected input in "x=(1 / 1 �"
I have the same issue with these sign : <- and * and minus, none of them are recognised.
You might be confronted to the so-called "zero-width space" which is not interpreted as a space. Check this wiki page:
If the blanks you have in your code example are this kind of character, it will make an error like this:
Error: unexpected input in "x=(1 / 1"
as some comments point out, one must be careful when pasting code from websites.

Unexpected Closing Bracket in R?

eCHFao<- -0.141081
#eCHFa1<-0
eCHFb1<- 0.985833
eCHFg1<- 0.199665
meanCHF<- mean(XtCHF)
eVarCHF<- (array,3421)
eVarCHF[1]<- var(XtCHF)
abco<- c(meanCHF, XtCHF1)
for (i in 2:3421) {eVarCHF[i]<- exp(eCHFao + (eCHFb1*log(sqrt(eVarCHF[i-1]))}
this code can't run because of an unexpected closing bracket, I am not sure why the bracket is unexpected or what I am missing?
May be a language problem since the thing that is unexpected is a curly-brace and what is missing are two closing parens (aka "brackets" in some parts of the English-speaking world):
exp(eCHFao + (eCHFb1*log(sqrt(eVarCHF[i-1]))
1 2 3 4 43 # need more parens
The language terms referring to ('s, and {'s is a bit scattered around the world. You should have posted the full error message that started out:
Error: unexpected '}'
... so it didn't actually say "bracket".

shiny-server: variable names are limited to 10000 bytes

I am getting error while running the code in shiny-server only. When I am running the same code from R console using runApp() function it is running well. See the error message below....
Warning: Error in assign: variable names are limited to 10000 bytes
Stack trace (innermost first):
46: assign
45: wrapFunctionLabel
44: public_bind_env$initialize
43: Observable$new
42: reactive
41: templateServer
40: server [/home/shiny-apps/ACCPlantAnalysis/server.R#20]
1: runApp
Error in assign(name, func, environment()) :
variable names are limited to 10000 bytes
Line no 41 and 40 are written by me. but other lines are not written by me; call from any reference library. I don't know from which library.
At last I got solution. I wrote functions for every 'if' block and put all code of 'if' block inside the function. Then call the function. And the was problem solved.
SectoralLeverageRatio(){
...
...
}
if (selectedIndex=="Sectoral Leverage Ratio"){
SectoralLeverageRatio()
}
The conclusion is... if your 'if' block is large enough and you got 'variable names are limited to 10000 bytes' error. Replace the code inside the 'if' block with user defined function.
This is the problem of shiny-server; not the problem of 'R'. If you run your code from 'R' console using runApp(), you would not get any error. But if you run through(production environment) you might get an error.
after a day long research I am able to pinpoint the issue. I have a long if..else block in my code. There are 10 if block and every if block has at least 6-8 line of code. When I comment one 'if' block of code (randomly chosen) the code running fantastically.... below is my 'if' block of code...
else if (selectedIndex=="Sectoral Leverage Ratio"){
## Calculated number of row of the matrix ##
rowNum <- selectedMonth[2] - selectedMonth[1] + 1
## Filter data based on criteria ##
filteredData <- subset(rawData,Year %in% selectedYear & Month %in% selectedMonth[1]:selectedMonth[2] & Plant %in% selectedPlant)
LeverageTable <- filteredData[,c('sch1ExpLeverage','sch2ExpLeverage','sch3ExpLeverage','sch4ExpLeverage','sch5ExpLeverage','sch7ExpLeverage','sch10ExpLeverage','sch11ExpLeverage')]
LeverageSum <- apply(LeverageTable,2,sum)
ExpTable <- filteredData[,c('sch1Exp','sch2Exp','sch3Exp','sch4Exp','sch5Exp','sch7Exp','sch10Exp','sch11Exp')]
ExpSum <- apply(ExpTable,2,sum)
LeverageRatio <- as.matrix(LeverageSum / ExpSum)
AvgLeverageRatio <- as.matrix((LeverageSum / ExpSum)/rowNum)
LeverageRatioTable <- cbind(LeverageRatio,AvgLeverageRatio)
colnames(LeverageRatioTable) <- c('Leverage Ratio','Avg.Leverage Ratio')
LeverageRatioTable <- data.frame(Sector=c('Health & Sant.','Edn. & Voc.','Social Welfare','Envt. Sust.','Hrtg & Arts','Sports','Rural Dvpt.','Admin Cost'),LeverageRatioTable)
as.data.frame(LeverageRatioTable)
}
All other 'if' blocks are almost similar (with some difference in calculation).
This is the problem of shiny-server; not the problem of 'R' itself.
If anybody wants to examin my code; I can share the full code.
According to ?name, you have to respect the fact that:
Names are limited to 10,000 bytes (and were to 256 bytes in versions of R before 2.13.0).
and the rule says in ?make.names:
A syntactically valid name consists of letters, numbers and the dot or
underline characters and starts with a letter or the dot not followed
by a number. Names such as ".2way" are not valid, and neither are the
reserved words.

Scilab Error 10000

Hi I am new to scilab and don't have much mathematical background.
I have been following code for another example and am being shown error 10000 for the following code:
function [z]=f(x,y)
z=0.026*(1.0-(y/ym))*y;
endfunction;
ym=12000;
x0=1950;y0=2555;xn=5;h=10;
x=[x0:h:xn];
y=ode("rk",y0,x0,x,f);
disp("x y")
disp("--------")
disp([x'y']);
function z=fe(x)
z=ym/(1-(1-ym/y0)*e^(-k*(t-t0)));
endfunction;
xe=(x0:h/10:xn);
n=length(xe)
for i=1:n
ye(i)=fe(xe(i));
end;
plot (x,y,'ro',xe, ye,'-b');legend ('rk4','Exact',3);
xtitle('solving dy/dx=k(1-y/ym)y','x','y');
I have worked through several other error messages. I am lost and don't know if the problem is in the code or the way I set up the problem. The following is the current error message:
!--error 10000
plot: Wrong size for input argument #2: A non empty matrix expected.
at line 57 of function checkXYPair called by :
at line 235 of function plot called by :
plot (x,y,'ro',xe, ye,'-b');legend ('rk4','Exact',3);
at line 25 of exec file called by :
I would appreciate any help.
Thanks
Start by adding clear as first statement, this will erase all variables before running your function. In the above script you don't declare ye.
Also the statement x=[x0:h:xn]; is strange with those values for x0,h and xn. You are now trying to get a list of x-values starting at 1950 and with positive steps of 10 up until 5 is reached.
I would recommend to try each line and see if the outcome is as expected. You do not need to know everything about the code, but probaly x and y should contain at least some values. The error is telling you that it expected a non-empty matrix for argument 2. This is y, so essentially it is telling you y is empty.

Resources