Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[, and ,]trigger an exception #18

Closed
lloyddewit opened this issue Sep 30, 2023 · 3 comments · Fixed by #23
Closed

[, and ,]trigger an exception #18

lloyddewit opened this issue Sep 30, 2023 · 3 comments · Fixed by #23

Comments

@lloyddewit
Copy link
Owner

The following line triggers an exception:

weather[,1]<-as.Date(weather[,1],format = "%m/%d/%Y")

For more details, please see IDEMSInternational/R-Instat#6619

@rdstern
Copy link

rdstern commented Oct 13, 2023

@lloyddewit I think I have a work-around we can use while we wait. It is from here.

a) It seems to imply that [. can be replaced by [[ ]] and then the comma can be omitted. So, in the example above:

weather[,1]<-as.Date(weather[,1],format = "%m/%d/%Y")

becomes:

weather[[1]]<-as.Date(weather[[1]],format = "%m/%d/%Y")

The opposite becomes [[contents with no comma]] [ ], so followed by empty double quotes.

I need to check this and can then report. If it works I'd like the work-around anyway, but it will also facilitate checking if there are other common problems to uncover.

@rdstern
Copy link

rdstern commented Oct 14, 2023

@lloyddewit The "solution" above doesn't work, but it fails in what might be a useful way?

Here is a short, but troublesome script, which includes a ,] feature.
a) If I comment out the line with the square brackets, it still doesn't work! I come back to that later.
b) Once it works (commenting out more lines) I tried the fix above. It didn't work, but gave a different error message.
I replaced
dat <- dat[order(dat$tree, dat$dir), ] by dat <- dat[[order(dat$tree, dat$dir)]][] as mentioned above:
Then it says:

image

If I put something inside the empty square brackets, e.g.

dat <- dat[[order(dat$tree, dat$dir)]][1]

then it is happy!
c) The second problem is a curly brackets problem on lines 8 to 11. If I replace them by ordinary brackets the problem goes away, but I don't know what happens to the R?

 library(agridat)
  data(box.cork)
  dat <- box.cork

  libs(reshape2, lattice)
  dat2 <- acast(dat, tree ~ dir, value.var='y')
  splom(dat2, pscales=3,
        prepanel.limits = function(x) c(25,100),
        main="box.cork", xlab="Cork yield on side of tree",
        panel=function(x,y,...){
          panel.splom(x,y,...)
          panel.abline(0,1,col="gray80")
        })


  ## Radial star plot, each tree is one line
  libs(plotrix)
  libs(reshape2)
  dat2 <- acast(dat, tree ~ dir, value.var='y')
  radial.plot(dat2, start=pi/2, rp.type='p', clockwise=TRUE,
              radial.lim=c(0,100), main="box.cork",
              lwd=2, labels=c('North','East','South','West'),
              line.col=rep(c("royalblue","red","#009900","dark orange",
                             "#999999","#a6761d","deep pink"),
                           length=nrow(dat2)))
  
  # asreml 4
  libs(asreml)

  # Unstructured covariance
  dat$dir <- factor(dat$dir)
  dat$tree <- factor(dat$tree)  
  dat <- dat[order(dat$tree, dat$dir), ]
  
  # Unstructured covariance matrix
  m1 <- asreml(y~dir, data=dat, residual = ~ tree:us(dir))
    
  libs(lucid)
  vc(m1)
    
  # Note: 'rcor' is a personal function to extract the correlations
  # into a matrix format
  # round(kw::rcor(m1)$dir, 2)
  #        E      N      S      W
  # E 219.93 223.75 229.06 171.37
  # N 223.75 290.41 288.44 226.27
  # S 229.06 288.44 350.00 259.54
  # W 171.37 226.27 259.54 226.00
    
  # Note: Wolfinger used a common diagonal variance
  
  # Factor Analytic with different specific variances
  # fixme: does not work with asreml4
  # m2 <- update(m1, residual = ~tree:facv(dir,1))
  # round(kw::rcor(m2)$dir, 2)
  #       E       N      S      W
  # E 219.94 209.46 232.85 182.27
  # N 209.46 290.41 291.82 228.43
  # S 232.85 291.82 349.99 253.94
  # W 182.27 228.43 253.94 225.99
    

@lloyddewit
Copy link
Owner Author

c) The second problem is a curly brackets problem on lines 8 to 11

@rdstern Thank you for all the test cases.
The root cause of the problem is the function keyword. RScript does not yet support keywords (see #19).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants