1

I have an object called modelTrain generated by the glm() function. This object has several other objects like: coefficients, formula, terms etc..

 modelTrain<- glm(Def90Adj ~ .-1,data=base,family=binomial(link='logit'))

I have to change the name of some variables keeping the values used for prediction. One of objects in modelTrain is of type 'call' (or 'language')

Its content is as follows:

attr(,"variables")
list(Def90Adj, `AveLncerLimiteRatio(0,1.04]`, `AveLncerLimiteRatio(1.04,3.96]`, 
`AveLncerLimiteRatio(11.4,40.3]`, `AveLncerLimiteRatio(3.96,11.4]`, 
`AveLncerLimiteRatio(40.3, Inf]`, `Ave6mEvoluçãoAvencerRatio(0, Inf]`, 
`Ven6mEvoluçãoVencidoRatio(0.0001, Inf]`, `Ven6mEvoluçãoVencidoRatio[-Inf,-0.0001]`, 
`Avvencer(0,1.01e+04]`, `AVBenNegAVenRatio(0, Inf]`, 
`AVeNnNociAVenRatio(0, Inf]`, LimDummy, VencidoDummy, 
PrejuDummy, AVedncerDummy)

I want to change the names with special characters like "Ven6mEvoluçãoVencidoRatio(0.0001, Inf]" to "Ven6mEvolucaoVencidoRatio(0.0001, Inf]" (without the special characters)

I tried copying the current content without the special characters

attr(modelTrain$terms, "variables") <- list((Def90Adj,AveLncerLimiteRatio(0,1.04]....

But it throws the error:

"Def90Adj" was not found.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
johnnyarth
  • 13
  • 5

1 Answers1

1

The brute-force method uses quote():

L1 <- quote(list(Def90Adj, `AveLncerLimiteRatio(0,1.04]`, `AveLncerLimiteRatio(1.04,3.96]`, 
`AveLncerLimiteRatio(11.4,40.3]`, `AveLncerLimiteRatio(3.96,11.4]`, 
`AveLncerLimiteRatio(40.3, Inf]`, `Ave6mEvolucaoAvencerRatio(0, Inf]`, 
`Ven6mEvolucaoVencidoRatio(0.0001, Inf]`, `Ven6mEvolucaoVencidoRatio[-Inf,-0.0001]`, 
`Avvencer(0,1.01e+04]`, `AVBenNegAVenRatio(0, Inf]`, 
`AVeNnNociAVenRatio(0, Inf]`, LimDummy, VencidoDummy, 
PrejuDummy, AVedncerDummy))

To do this programatically, you need something like:

for (i in 2:length(L1)) {
    L1[[i]] <- substitute(x,list(x=gsub("V","v",deparse(L1[[i]]))))
}

(this example just changes uppercase V to lowercase v ...)

Answers to this question suggest that stringi::stri_trans_general(x,"Latin-ASCII") will convert accented characters to their non-accented analogues ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453