GithubHelp home page GithubHelp logo

codeanalysis's Introduction

codeanalysis's People

Contributors

clarkfitzg avatar duncantl avatar mespe avatar nick-ulle avatar vsbuffalo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeanalysis's Issues

Handle for loops without braces

The code for for loops with assignments assumes that a brace contains the body of a loop. This should be a straightforward fix, I'm just opening this so that I remember to do it. While I'm at it I should put the documentation in the proper place.

# with brace is fine
> forLoopToLapply(quote(for(i in 1:5){ z[[i]] = i}))                                              
z[1:5] <- lapply(1:5, function(i) {
    i
})

> forLoopToLapply(quote(for(i in 1:5) z[[i]] = i))
Error in expr[[1]] : object of type 'symbol' is not subsettable

Enter a frame number, or 0 to exit   

1: forLoopToLapply(quote(for (i in 1:5) z[[i]] = i))
2: forLoopWithUpdates(forloop, deps)
3: isSimpleIndexAssign(lastline, global_update, ivar)

# no assignment, no brace works
> forLoopToLapply(quote(for(i in 1:5) print(i)))
lapply(1:5, function(i) print(i))

getDepends() does not work in many cases

CodeAnalysis::getDepends() seems to miss quite a few statements, such as write.table(), ggsave(), or could not gather the filename properly if it's not specified explicitly by file = value.

For example, this file test_getDepends_example_script.R with the following content

# pardon the syntax, it's for static analysis testing only
X = data.frame('name' = c('a', 'b', 'c'), 'value' = c(1:3))

read.table('file_1.csv')
read.table(file = 'file_2.csv')
read.csv('file_3.csv')
read.csv(file = 'file_4.csv')
write.table('file_5.csv')
write.table(file = 'file_6.csv')
write.csv(X, 'file_7.csv')
write.csv(X, file = 'file_8.csv')

p = ggplot2::ggplot(X) +
  geom_point(aes(x=name,y=value))

ggplot2::ggsave(filename = 'a_plot.png', plot = p)

when tested with CodeAnalysis::getDepends('test_getDepends_example_script.R'), will result in the following

    filename  operation expressionNum
1 file_1.csv read.table             2
2 file_2.csv read.table             3
3 file_3.csv   read.csv             4
4 file_4.csv   read.csv             5
5       <NA>  write.csv             8
6 file_8.csv  write.csv             9

---------- The following code will create the necessary files to reproduce the issue ----------

cat > test_getDepends_example_script.R <<EOL
# pardon the syntax, it's for static analysis testing only
X = data.frame('name' = c('a', 'b', 'c'), 'value' = c(1:3))

read.table('file_1.csv')
read.table(file = 'file_2.csv')
read.csv('file_3.csv')
read.csv(file = 'file_4.csv')
write.table('file_5.csv')
write.table(file = 'file_6.csv')
write.csv(X, 'file_7.csv')
write.csv(X, file = 'file_8.csv')

p = ggplot2::ggplot(X) +
  geom_point(aes(x=name,y=value))

ggplot2::ggsave(filename = 'a_plot.png', plot = p)
EOL

cat > test_getDepends.R <<EOL
CodeAnalysis::getDepends('test_getDepends_example_script.R')
EOL

How to enforce version checking on package install?

I've been using the recent changes to rstatic that @nick-ulle has made, and I'd like to make sure CodeAnalysis has the correct version of rstatic.

I added this line to the DESCRIPTION:

Imports: CodeDepends, rstatic (>= 0.0.0.9052)

This versioning doesn't seem to be enforced when I run R CMD INSTALL from the command line, when I load the package with library, or when I call the functions that use rstatic::. That is, I change the line to require rstatic (>= 1.0), which doesn't exist, and R never complains that I don't have that version.

This happens with R 3.5.3 on my local Mac, and R 3.6.0 on Linux.

The R Extensions manual has a section on package dependencies that says:

Version requirements can be specified and are checked when the namespace is loaded (since R >= 3.0.0).

What am I doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.