Skip to content

getDepends() does not work in many cases #4

@ttdtrang

Description

@ttdtrang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions