I am unable to install library(raster) getting error Error: unexpected '==' in "=="

I am unable to install library(raster) getting error Error: unexpected '==' in "==" . I have installed terra package

Can you please post the exact command you are using and the complete console output you get when you try to install it?

This is the entire code i have used and on last line where i am trying to install the library

#Examine data
dat<- read.csv("C:/Users/souvi/OneDrive/Desktop/r data/telco(1).csv")
head(dat)

install.packages("plyr",dep=T)
library(plyr)
library(rpart)
library(lattice)
library(ggplot2)
install.packages("Rcpp",dep=T)
library(Rcpp)

install.packages("caret",dep=T)
library(caret)
library(rpart)
install.packages("gridExtrat",dep=T)
library(gridExtra)

install.packages("rpart.plot",dep=T)
library(rpart.plot)

#Data Wrangling and Data Munging

datc <- dat[complete.cases(dat),]

datc$SeniorCitizen <- as.factor(mapvalues(datc$SeniorCitizen,

                                      from=c("0","1"),
                                      
                                      to=c("No", "Yes")))

datc$MultipleLines <- as.factor(mapvalues(datc$MultipleLines,

                                      from=c("No phone service"),
                                      
                                      to=c("No")))

for(i in 10:15){

datc[,i] <- as.factor(mapvalues(datc[,i],

                              from= c("No internet service"), to= c("No")))

}

View(datc)

datc$customerID <- NULL
library(caret)
library(ggplot2)
library(lattice)

set.seed(56)
split_train_test <- createDataPartition(datc$Churn,p=0.7,list=FALSE)
dtrain<- datc[split_train_test,]
dtest<- datc[-split_train_test,]

#Gender plot

p1 <- ggplot(datc, aes(x = gender)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)
p1

#Senior citizen plot

p2 <- ggplot(datc, aes(x = SeniorCitizen)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)
#Partner plot

p3 <- ggplot(datc, aes(x = Partner)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Dependents plot

p4 <- ggplot(datc, aes(x = Dependents)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)
library(gridExtra)

#Plot demographic data within a grid

grid.arrange(p1, p2, p3, p4, ncol=2)

#Services Plot

#Phone service plot

p5 <- ggplot(datc, aes(x = PhoneService)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Multiple phone lines plot

p6 <- ggplot(datc, aes(x = MultipleLines)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Internet service plot

p7 <- ggplot(datc, aes(x = InternetService)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Online security service plot

p8 <- ggplot(datc, aes(x = OnlineSecurity)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Online backup service plot

p9 <- ggplot(datc, aes(x = OnlineBackup)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Device Protection service plot

p10 <- ggplot(datc, aes(x = DeviceProtection)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Tech Support service plot

p11 <- ggplot(datc, aes(x = TechSupport)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

library(ggplot2)

#Streaming TV service plot

p12 <- ggplot(datc, aes(x = StreamingTV)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Streaming Movies service plot

p13 <- ggplot(datc, aes(x = StreamingMovies)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Plot service data within a grid

grid.arrange(p5, p6, p7,p8, p9, p10,p11, p12, p13,ncol=3)

#Contract status plot

p14 <- ggplot(datc, aes(x = Contract)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Paperless billing plot

p15 <- ggplot(datc, aes(x = PaperlessBilling)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Payment method plot

p16 <- ggplot(datc, aes(x = PaymentMethod)) +
geom_bar(fill="#FF6666") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Plot contract data within a grid

grid.arrange(p14, p15, p16, ncol=1)

#Tenure histogram

p17 <- ggplot(datc, aes(x = tenure)) +
geom_histogram(fill="red",binwidth = 1) +
labs(x = "Months",
title = "Tenure Distribtion")

#Monthly charges histogram

p18 <- ggplot(datc, aes(x = MonthlyCharges)) +
geom_histogram(fill="red",binwidth = 5) +
labs(x = "Dollars (binwidth = 5)",
title = "Monthly charges Distribtion")

#Total charges histogram

p19 <- ggplot(datc, aes(x = TotalCharges)) +
geom_histogram(fill="red",binwidth = 100) +
labs(x = "Dollars (binwidth = 100)",
title = "Total charges Distribtion")

#Plot quantitative data within a grid
library(gridExtra)
grid.arrange(p17, p18, p19, ncol=1)

#Churn variable

p20 <- ggplot(datc, aes(x = Churn)) +
geom_bar(fill="orange") +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

p20
library(ggplot2)

#Gender plot
p1 <- ggplot(datc, aes(x = gender)) +
geom_bar(aes(fill = Churn)) +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Senior citizen plot
p2 <- ggplot(datc, aes(x = SeniorCitizen)) +
geom_bar(aes(fill = Churn)) +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Partner plot
p3 <- ggplot(datc, aes(x = Partner)) +
geom_bar(aes(fill = Churn)) +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Dependents plot
p4 <- ggplot(datc, aes(x = Dependents)) +
geom_bar(aes(fill = Churn)) +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3)

#Plot demographic data within a grid
grid.arrange(p1, p2, p3, p4, ncol=2)

install.packages("corrplot")

library(dplyr)
library(psych)
library(corrplot)
library(plyr)
datc %>%
dplyr::select (TotalCharges, MonthlyCharges, tenure) %>%
cor() %>%
corrplot.mixed(upper = "circle", tl.col = "black", number.cex = 0.7)

#Decision tree

#classification model-Decision tree
library(rpart)
tr_fit <- rpart(Churn ~., data=dtrain, method="class")
rpart.plot(tr_fit)
library(rpart)

tr_prob1 <-predict(tr_fit, dtest)
tr_prob1

#Confusion matrix
tr_pred1 <- ifelse(tr_prob1[,2] > 0.5,"Yes","No")
table(Predicted = tr_pred1, Actual = dtest$Churn)
library(caret)
library(lattice)
#overall Accuracy of the model
tr_prob2 <- predict(tr_fit, dtrain)
tr_pred2 <- ifelse(tr_prob2[,2] > 0.5,"Yes","No")
tr_tab1 <- table(Predicted = tr_pred2, Actual = dtrain$Churn)
tr_tab2 <- table(Predicted = tr_pred1, Actual = dtest$Churn)

Train

confusionMatrix(
as.factor(tr_pred2),
as.factor(dtrain$Churn),
positive = "Yes"
)

library(ggplot2)

End of the Model

p21 <- ggplot(datc, aes(x = Contract, fill = Churn)) +
geom_bar() +
geom_text(aes(y = ..count.. -200,
label = paste0(round(prop.table(..count..),4) * 100, '%')),
stat = 'count',
position = position_dodge(.1),
size = 3) +
labs(title="Churn rate by contract status")

library(ConfusionTableR)
p21

#Logistic regression

library (raster)

And output is below

> #Logistic regression
> =====================
Error: unexpected '==' in "=="

Sorry but I don't see how this is relevant to your original question, this does not seem to have anything to do with package installation issues but with a syntax error in your code, sadly I'm not able to eyeball it.

To help us help you, could you please turn this into a proper reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

I couldn't see it because you hadn't formatted your post but after further inspection I can see that you haven't commented out the underlinening (=====================) and R is trying to execute it as code, either remove it or add the comment symbol in front of it (#=====================)

Thank you , appreciate your help , i see adding the underline is the reason , i am getting few more error after executing that line

glm=(Chrun1 ~., data=dtrain,family=binomial(link='logit'))
Error: unexpected ',' in "glm=(Chrun1 ~.,"

Proper application of ,

lr_fit=glm(Churn ~.,data=dtrain,family=binomial(link='logit'))
Error in eval(family$initialize) : y values must be 0 <= y <= 1
glm=(Chrun1 ~., data=dtrain,family=binomial(link='logit'))
Error: unexpected ',' in "glm=(Chrun1 ~.,"
lr_fit=glm(Churn ~.,data=dtrain,family=binomial(link='logit'))
Error in eval(family$initialize) : y values must be 0 <= y <= 1
glm=(Chrun ~., data=dtrain,family=binomial(link='logit'))
Error: unexpected ',' in "glm=(Chrun ~.,"
#Convert Dep Var into Numeric
datc$Chrun1=as.factor(mapvalues(datc$Chrun,from=c("No","Yes"),to=c(0,1)))
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'as.factor': could not find function "mapvalues"
dtrain$Churn=NULL
datc$Chrun1=as.factor(mapvalues(datc$Chrun,from=c("No","Yes"),to=c(0,1)))
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'as.factor': could not find function "mapvalues"
lr_prob1=predict(lr_fit,dtest,type="response")
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'object' in selecting a method for function 'predict': object 'lr_fit' not found
lr_prob1=ifelts(lr_prob1=0.5,"Yes","No")
Error in ifelts(lr_prob1 = 0.5, "Yes", "No") :
could not find function "ifelts"
table(Predict=lr_pred1,Actual=dtest$Churn)
Error in table(Predict = lr_pred1, Actual = dtest$Churn) :
object 'lr_pred1' not found
library(rpart)
#Prediction Accuracy_to check overfitting problem
lr_prob2=predict(lr_fit,dtrain,type="response")
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'object' in selecting a method for function 'predict': object 'lr_fit' not found
lr_pred2=ifelse(lr_prob2=0.5,"Yes","No")
Error in ifelse(lr_prob2 = 0.5, "Yes", "No") :
unused argument (lr_prob2 = 0.5)
lr_pred2=ifelse(lr_prob2=0.5,"Yes","No")
Error in ifelse(lr_prob2 = 0.5, "Yes", "No") :
unused argument (lr_prob2 = 0.5)
confusionMatrix(as.factor(lr_pred2),as.factor(dtrain$Churn1),positive = "Yes")
Error in confusionMatrix(as.factor(lr_pred2), as.factor(dtrain$Churn1), :
could not find function "confusionMatrix"

please suggest

Those are more syntax errors but you are not showing the line of code that is causing the problem so it would be hard for us to help you with that. I think you should start by learning the basics of the R programming language so you can identify syntax errors by yourself.

it seems that you have a rogue = after glm
should be

glm(Chrun1 ~., data=dtrain,family=binomial(link='logit'))

Appreciate your help !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.