duncantl / codeanalysis Goto Github PK
View Code? Open in Web Editor NEWTools for static analysis of R code
License: Other
Tools for static analysis of R code
License: Other
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))
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.