Skip to content

Commit 2166cc8

Browse files
authored
Merge pull request #43 from atsyplenkov/feat-air
feat: add #fmt:skip for R tables (closes #16)
2 parents e79c806 + 9b693ce commit 2166cc8

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"publisher": "atsyplenkov",
77
"license": "MIT",
88
"pricing": "Free",
9-
"sponsor": {
10-
"url": "https://github.com/sponsors/atsyplenkov"
11-
},
129
"icon": "assets/logo.png",
1310
"repository": {
1411
"type": "git",
@@ -106,6 +103,11 @@
106103
"default": true,
107104
"markdownDescription": "Show the `Pastum: paste as default dataframe` command in the editor context menu *(i.e., right-click menu)*. It will only appear in R, Python, and Julia editors. The dataframe will be pasted according to the specified `pastum.defaultDataframeR` and `pastum.defaultDataframePy`."
108105
},
106+
"pastum.airFormat": {
107+
"type": "boolean",
108+
"default": true,
109+
"markdownDescription": "Add comment to skip air formatting in R. (i.e., `# fmt:skip`) before the pasted dataframe."
110+
},
109111
"pastum.defaultDataframeR": {
110112
"type": "string",
111113
"enum": [

src/paste-r.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ async function clipboardToRDataFrame(framework = null) {
7474
*/
7575
function createRDataFrame(tableData, framework) {
7676
const { headers, data, columnTypes } = tableData;
77-
let code = "";
77+
const config = vscode.workspace.getConfiguration("pastum");
78+
const airFormat = config.get("airFormat");
79+
80+
let code = airFormat ? "# fmt:skip\n" : "";
81+
// let code = "";
7882

7983
/**
8084
* Formats a value according to its column type for R syntax
@@ -118,26 +122,24 @@ function createRDataFrame(tableData, framework) {
118122

119123
// Generate code based on selected framework
120124
if (framework === "base") {
121-
code = `data.frame(\n`;
125+
code += `data.frame(\n`;
122126
headers.forEach((header, i) => {
123127
const values = data.map((row) => formatValue(row[i], i)).join(", ");
124-
code += ` ${header} = c(${values})${
125-
i < headers.length - 1 ? ",\n" : "\n"
126-
}`;
128+
code += ` ${header} = c(${values})${i < headers.length - 1 ? ",\n" : "\n"
129+
}`;
127130
});
128131
code += `)`;
129132
} else if (framework === "tibble") {
130-
code = `tibble::tibble(\n`;
133+
code += `tibble::tibble(\n`;
131134
headers.forEach((header, i) => {
132135
const values = data.map((row) => formatValue(row[i], i)).join(", ");
133-
code += ` ${header} = c(${values})${
134-
i < headers.length - 1 ? ",\n" : "\n"
135-
}`;
136+
code += ` ${header} = c(${values})${i < headers.length - 1 ? ",\n" : "\n"
137+
}`;
136138
});
137139
code += `)`;
138140
} else if (framework === "tribble") {
139141
const colWidths = calculateColumnWidths();
140-
code = `tibble::tribble(\n`;
142+
code += `tibble::tribble(\n`;
141143

142144
// Column headers with padding
143145
code +=
@@ -162,21 +164,19 @@ function createRDataFrame(tableData, framework) {
162164
// Remove trailing comma and close parentheses
163165
code = code.trimEnd().slice(0, -1) + `\n)`;
164166
} else if (framework === "data.table") {
165-
code = `data.table::data.table(\n`;
167+
code += `data.table::data.table(\n`;
166168
headers.forEach((header, i) => {
167169
const values = data.map((row) => formatValue(row[i], i)).join(", ");
168-
code += ` ${header} = c(${values})${
169-
i < headers.length - 1 ? ",\n" : "\n"
170-
}`;
170+
code += ` ${header} = c(${values})${i < headers.length - 1 ? ",\n" : "\n"
171+
}`;
171172
});
172173
code += `)`;
173174
} else if (framework === "polars") {
174-
code = `polars::pl$DataFrame(\n`;
175+
code += `polars::pl$DataFrame(\n`;
175176
headers.forEach((header, i) => {
176177
const values = data.map((row) => formatValue(row[i], i)).join(", ");
177-
code += ` ${header} = c(${values})${
178-
i < headers.length - 1 ? ",\n" : "\n"
179-
}`;
178+
code += ` ${header} = c(${values})${i < headers.length - 1 ? ",\n" : "\n"
179+
}`;
180180
});
181181
code += `)`;
182182
}

0 commit comments

Comments
 (0)