Skip to content

Commit f11ab45

Browse files
authored
Increae Support for the Dependency Query and Plot Creation (#1429)
* feat(plots): add much more of the graphics functions to support * feat(dep): a lot of additions to the dependency query Support for only partial dependencies (if arguments fit)
1 parent 47dbfce commit f11ab45

File tree

4 files changed

+102
-6
lines changed

4 files changed

+102
-6
lines changed

src/dataflow/environments/default-builtin-config.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@ import type { DataflowGraphVertexFunctionCall } from '../graph/vertex';
77
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
88
import { CascadeAction } from '../../queries/catalog/call-context-query/cascade-action';
99

10-
const PlotCreate = ['plot', 'plot.new', 'xspline', '', 'curve', 'map', 'image', 'boxplot', 'dotchart', 'sunflowerplot', 'barplot', 'matplot', 'hist', 'stem', 'density', 'smoothScatter', 'contour', 'persp'] as const;
11-
const GraphicDeviceOpen = ['pdf', 'jpeg', 'png', 'windows', 'postscript', 'xfig', 'bitmap', 'pictex', 'cairo_pdf', 'svg', 'bmp', 'tiff', 'X11', 'quartz', 'image_graph', 'image_draw', 'dev.new'] as const;
12-
const PlotAddons = ['points', 'abline', 'map', 'mtext', 'lines', 'text', 'legend', 'title', 'axis', 'polygon', 'polypath', 'pie', 'rect', 'segments', 'arrows', 'symbols', 'tiplabels'] as const;
10+
const PlotCreate = [
11+
'plot', 'plot.new', 'xspline', 'curve', 'map', 'image', 'boxplot', 'dotchart', 'sunflowerplot', 'barplot', 'matplot', 'hist', 'stem',
12+
'density', 'smoothScatter', 'contour', 'persp', 'XYPlot', 'xyplot', 'stripplot', 'bwplot', 'dotPlot', 'histPlot', 'densityPlot', 'qqPlot', 'boxPlot',
13+
'bxp', 'assocplot', 'mosaicplot', 'stripchart', 'fourfoldplot', 'mosaicplot', 'plot.xy', 'plot.formula', 'plot.default', 'plot.design', 'stars',
14+
'spineplot', 'Plotranges'
15+
] as const;
16+
const GraphicDeviceOpen = [
17+
'pdf', 'jpeg', 'png', 'windows', 'postscript', 'xfig', 'bitmap', 'pictex', 'cairo_pdf', 'svg', 'bmp', 'tiff', 'X11', 'quartz', 'image_graph',
18+
'image_draw', 'dev.new', 'trellis.device'
19+
] as const;
20+
const PlotAddons = [
21+
'points', 'abline', 'map', 'mtext', 'lines', 'text', 'legend', 'title', 'axis', 'polygon', 'polypath', 'pie', 'rect', 'segments', 'arrows', 'symbols',
22+
'tiplabels', 'rug'
23+
] as const;
1324

1425
function toRegex(n: readonly string[]): RegExp {
1526
return new RegExp(`^(${
16-
n.map(s => s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')).filter(s => s.length > 0).join('|')
27+
[...new Set(n)].map(s => s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')).filter(s => s.length > 0).join('|')
1728
})$`);
1829
}
1930

@@ -33,7 +44,8 @@ export const DefaultBuiltinConfig: BuiltInDefinitions = [
3344
'unique', 'paste', 'paste0', 'read.csv', 'stop', 'is.null', 'numeric', 'as.character', 'as.integer', 'as.logical', 'as.numeric', 'as.matrix',
3445
'rbind', 'nrow', 'ncol', 'tryCatch', 'expression', 'factor',
3546
'missing', 'as.data.frame', 'data.frame', 'na.omit', 'rownames', 'names', 'order', 'length', 'any', 'dim', 'matrix', 'cbind', 'nchar',
36-
'pdf', 'jpeg', 'png', 'windows', 'postscript', 'xfig', 'bitmap', 'pictex', 'cairo_pdf', 'svg', 'bmp', 'tiff', 'X11', 'quartz'
47+
'pdf', 'jpeg', 'png', 'windows', 'postscript', 'xfig', 'bitmap', 'pictex', 'cairo_pdf', 'svg', 'bmp', 'tiff', 'X11', 'quartz',
48+
'jitter'
3749
],
3850
processor: 'builtin:default',
3951
config: { readAllArguments: true },

src/queries/catalog/dependencies-query/dependencies-query-executor.ts

+3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ function getResults<T extends DependencyInfo>(data: BasicQueryData, results: Cal
165165

166166
const foundValues = linkedArgs ?? args;
167167
if(!foundValues) {
168+
if(info.ignoreIf === 'arg-missing') {
169+
return [];
170+
}
168171
const record = compactRecord(makeInfo(id, vertex, undefined, undefined, dropInfoOnLinkedIds(linkedIds)));
169172
return record ? [record as T] : [];
170173
}

src/queries/catalog/dependencies-query/dependencies-query-format.ts

+77-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const SourceFunctions: FunctionInfo[] = [
4141
{ name: 'sys.source', argIdx: 0, argName: 'file', resolveValue: true }
4242
] as const;
4343
export const ReadFunctions: FunctionInfo[] = [
44+
{ name: 'parse', argName: 'file', resolveValue: true, ignoreIf: 'arg-missing' },
4445
{ name: 'read.table', argIdx: 0, argName: 'file', resolveValue: true },
4546
{ name: 'read.csv', argIdx: 0, argName: 'file', resolveValue: true },
4647
{ name: 'read.csv2', argIdx: 0, argName: 'file', resolveValue: true },
@@ -71,8 +72,9 @@ export const ReadFunctions: FunctionInfo[] = [
7172
{ name: 'read_tsv', argIdx: 0, argName: 'file', resolveValue: true },
7273
{ name: 'read_table', argIdx: 0, argName: 'file', resolveValue: true },
7374
{ name: 'read_log', argIdx: 0, argName: 'file', resolveValue: true },
74-
{ name: 'read_lines', argIdx: 0, argName: 'file', resolveValue: true },
75+
{ name: 'read_lines_raw', argIdx: 0, argName: 'file', resolveValue: true },
7576
{ name: 'read_lines_chunked', argIdx: 0, argName: 'file', resolveValue: true },
77+
{ name: 'read_rds', argIdx: 0, argName: 'file', resolveValue: true },
7678
// xlsx
7779
{ name: 'read.xlsx', argIdx: 0, argName: 'file', resolveValue: true },
7880
{ name: 'read.xlsx2', argIdx: 0, argName: 'file', resolveValue: true },
@@ -104,6 +106,49 @@ export const ReadFunctions: FunctionInfo[] = [
104106
{ name: 'image_read_svg', argIdx: 0, argName: 'path', resolveValue: true },
105107
{ name: 'image_read_pdf', argIdx: 0, argName: 'path', resolveValue: true },
106108
{ name: 'image_read_video', argIdx: 0, argName: 'path', resolveValue: true },
109+
// LIM
110+
{ name: 'Read', argIdx: 0, argName: 'file', resolveValue: true },
111+
// sourcetools,
112+
{ name: 'read', argIdx: 0, argName: 'path', resolveValue: true },
113+
{ name: 'read_lines', argIdx: 0, argName: 'path', resolveValue: true },
114+
{ name: 'read_bytes', argIdx: 0, argName: 'path', resolveValue: true },
115+
{ name: 'read_lines_bytes', argIdx: 0, argName: 'path', resolveValue: true },
116+
{ name: 'tokenize', argName: 'file', resolveValue: true, ignoreIf: 'arg-missing' },
117+
{ name: 'tokenize_file', argIdx: 0, argName: 'path', resolveValue: true },
118+
// expss
119+
{ name: 'read_spss', argIdx: 0, argName: 'file', resolveValue: true },
120+
{ name: 'read_spss_to_list', argIdx: 0, argName: 'file', resolveValue: true },
121+
// SimPhe
122+
{ name: 'read.geno', argIdx: 0, argName: 'fname', resolveValue: true },
123+
// ape
124+
{ name: 'read.tree', argName: 'file', resolveValue: true, ignoreIf: 'arg-missing' },
125+
// geomorph
126+
{ name: 'readland.tps', argIdx: 0, argName: 'file', resolveValue: true },
127+
// readxl
128+
{ name: 'read_excel', argIdx: 0, argName: 'path', resolveValue: true },
129+
{ name: 'read_xls', argIdx: 0, argName: 'path', resolveValue: true },
130+
{ name: 'read_xlsx', argIdx: 0, argName: 'path', resolveValue: true },
131+
// sf
132+
{ name: 'read.sf', argIdx: 0, argName: 'dsn', resolveValue: true },
133+
{ name: 'st_read', argIdx: 0, argName: 'dsn', resolveValue: true },
134+
// rgdal
135+
{ name: 'readOGR', argIdx: 0, argName: 'dsn', resolveValue: true },
136+
{ name: 'ogrInfo', argIdx: 0, argName: 'dsn', resolveValue: true },
137+
{ name: 'ogrFIDs', argIdx: 0, argName: 'dsn', resolveValue: true },
138+
{ name: 'OGRSpatialRef', argIdx: 0, argName: 'dsn', resolveValue: true },
139+
{ name: 'ogrListLayers', argIdx: 0, argName: 'dsn', resolveValue: true },
140+
{ name: 'readGDAL', argIdx: 0, argName: 'fname', resolveValue: true },
141+
// readstata13
142+
{ name: 'read.dta13', argIdx: 0, argName: 'file', resolveValue: true },
143+
// arrow
144+
{ name: 'read_parquet', argIdx: 0, argName: 'file', resolveValue: true },
145+
// maptools
146+
{ name: 'readShapePoly', argIdx: 0, argName: 'fn', resolveValue: true },
147+
// XLConnect
148+
{ name: 'readWorksheetFromFile', argIdx: 0, argName: 'file', resolveValue: true },
149+
{ name: 'readNamedRegionFromFile', argIdx: 0, argName: 'file', resolveValue: true },
150+
{ name: 'loadWorkbook', argIdx: 0, argName: 'filename', resolveValue: true },
151+
107152
] as const;
108153

109154
const OutputRedirects = [
@@ -133,6 +178,8 @@ export const WriteFunctions: FunctionInfo[] = [
133178
{ name: 'write_tsv', argIdx: 1, argName: 'file', resolveValue: true },
134179
{ name: 'write_table', argIdx: 1, argName: 'file', resolveValue: true },
135180
{ name: 'write_log', argIdx: 1, argName: 'file', resolveValue: true },
181+
{ name: 'write_lines', argIdx: 1, argName: 'file', resolveValue: true },
182+
{ name: 'write_rds', argIdx: 1, argName: 'file', resolveValue: true },
136183
// heaven
137184
{ name: 'write_sas', argIdx: 1, argName: 'file', resolveValue: true },
138185
{ name: 'write_sav', argIdx: 1, argName: 'file', resolveValue: true },
@@ -166,14 +213,43 @@ export const WriteFunctions: FunctionInfo[] = [
166213
{ name: 'quartz', argIdx: 0, argName: 'file', resolveValue: true },
167214
// car
168215
{ name: 'Export', argIdx: 0, argName: 'file', resolveValue: true },
216+
// LIM
217+
{ name: 'PrintMat', linkTo: OutputRedirects, resolveValue: true },
218+
// sjmisc
219+
{ name: 'write_spss', argIdx: 1, argName: 'path', resolveValue: true },
220+
{ name: 'write_stata', argIdx: 1, argName: 'path', resolveValue: true },
221+
{ name: 'write_sas', argIdx: 1, argName: 'path', resolveValue: true },
222+
// ape
223+
{ name: 'write.tree', argIdx: 1, argName: 'file', resolveValue: true },
224+
{ name: 'write.nexus', argIdx: 1, argName: 'file', resolveValue: true },
225+
{ name: 'write.phyloXML', argIdx: 1, argName: 'file', resolveValue: true },
226+
// Claddis
227+
{ name: 'write_nexus_matrix', argIdx: 1, argName: 'file_name', resolveValue: true },
228+
{ name: 'write_tnt_matrix', argIdx: 1, argName: 'file_name', resolveValue: true },
229+
// rgdal
230+
{ name: 'writeOGR', argIdx: 1, argName: 'dsn', resolveValue: true },
231+
{ name: 'writeGDAL', argIdx: 1, argName: 'fname', resolveValue: true },
232+
// arrow
233+
{ name: 'write_parquet', argIdx: 1, argName: 'sink', resolveValue: true },
234+
// sf
235+
{ name: 'st_write', argIdx: 1, argName: 'dsn', resolveValue: true },
236+
{ name: 'write_sf', argIdx: 1, argName: 'dsn', resolveValue: true, ignoreIf: 'arg-missing' },
237+
// maptools
238+
{ name: 'writePolyShape', argIdx: 1, argName: 'fn', resolveValue: true },
239+
// XLConnect
240+
{ name: 'writeNamedRegionToFile', argIdx: 0, argName: 'file', resolveValue: true },
241+
{ name: ' writeWorksheetToFile', argIdx: 0, argName: 'file', resolveValue: true },
169242
] as const;
170243

171244
export interface FunctionInfo {
172245
name: string
246+
/** the index if the argument can be positional, unnamed in case of something like `...`, if the argument must be given with the name, please leave undefined */
173247
argIdx?: number | 'unnamed'
174248
argName?: string
175249
linkTo?: DependencyInfoLink[]
176250
resolveValue?: boolean | 'library'
251+
// the function is not to be counted as a dependency if the argument is missing
252+
ignoreIf?: 'arg-missing'
177253
}
178254

179255
export interface DependenciesQuery extends BaseQueryFormat {

test/functionality/dataflow/query/dependencies-query.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ describe.sequential('Dependencies Query', withShell(shell => {
144144

145145
testQuery('unknown read', 'read.table(x)', { readData: [{ nodeId: '[email protected]', functionName: 'read.table', source: 'unknown', lexemeOfArgument: 'x' }] });
146146

147+
describe('Only if file parameter', () => {
148+
testQuery('parse', 'parse(file="test.R")', { readData: [{ nodeId: '1@parse', functionName: 'parse', source: 'test.R' }] });
149+
testQuery('parse text', 'parse(text="test.R")', { });
150+
});
151+
147152
describe('Custom', () => {
148153
const readCustomFile: Partial<DependenciesQuery> = {
149154
readFunctions: [{ name: 'read.custom.file', argIdx: 1, argName: 'file' }]

0 commit comments

Comments
 (0)