dput() concatenated vector with no quotes, separated by commas in R

An oddly specific task – I have a dataframe with columns with values I need to concatenate in order to prepare a query for a website that requires very specific inputs: unquoted strings, separated by commas. Here’s a dput() of a subset of the dataframe with the columns needed:

d = structure(list(CodeSpace = c(1303L, 1303L, 1303L, 1303L, 1303L,  1303L), TagID = c(23041L, 23042L, 23044L, 23046L, 23043L, 23045L )), class = "data.frame", row.names = c(NA, -6L)) 

The output I need is:

A69-1303-23041, A69-1303-23042, A69-1303-23044, A69-1303-23046, A69-1303-23043, A69-1303-23045 

I can approximate it (though I end up with a trailing comma) with:

cat(paste0(noquote(paste("A69", d$  CodeSpace, d$  TagID, sep = "-")) , ",")) 

Is there a better (i.e. more principled) way to do this?

How overly-cute and/or heisenbug-laden is this method of adding commas to integers (12345 -> 12,345)?

Beginner/occasional C tinkerer here. (Reasonably comfortable with scripting languages, tend to avoid C due to its terseness, but trying to work past that.)

So, I happened to want to insert commas into some integers (a, uh… few hours ago). I got curious about various interesting (non-string-based) ways one might achieve that, found how to arithmetically reverse a string (cool), and, uh… ended up here.

I made this. I don’t know if I should keep it?

#include <stdio.h>  int fmtn(unsigned long long n, char *buf, int maxlen) {      int l = 0;     for (unsigned long long x = n; x; x /= 10, l++);      int l2 = l + (int)((l / 3.1));     if (l2 > maxlen) l2 = maxlen;     if (l > maxlen) l = maxlen;      int o = l2 - 1;     int c = l - 1;      for (; o > 0, n; c--, n /= 10) {         if (o >= 0) buf[o--] = (n % 10) + 48;         if (o >= 0 && (l - c) % 3 == 0) buf[o--] = ',';     }      buf[l2] = '';      return l2;  }  #define test(x) do { fmtn(x, b, 30); printf("\"%s\"\n", b); } while(0); #define testn(x, n) do { fmtn(x, b, n); printf("\"%s\"\n", b); } while(0);  int main(int argc, char **argv) {      char b[30];      testn(123, 1);     testn(123, 2);     testn(1234, 3);     testn(1234, 4);     testn(1234, 5);      puts("");      test(123);     test(12345);     test(123456);     test(1234567);     test(12345678);     test(123456789);     test(1234567890);     test(12345678901);     test(123456789012);     test(1234567890123);     test(12345678901234);     test(123456789012345);     test(1234567890123456);     test(12345678901234567);     test(123456789012345678);     test(1234567890123456789);     test(12345678901234567890ull);  }  

Compiling with -Wall produces this interesting message – I’m pretty sure that o will routinely <= 0:

In function 'fmtn': 15:14: warning: left-hand operand of comma expression has no effect [-Wunused-value]   for (; o > 0, n; c--, n /= 10) {               ^ 

Here’s what the supplied main outputs on my machine. The first part is a demonstration of what happens when maxlen (which doesn’t count the '') is too short (no buffer overflows! yay!):

"3" "23" "234" ",234" "1,234"  "123" "12,345" "123,456" "1,234,567" "12,345,678" "123,456,789" "1,234,567,890" "12,345,678,901" "123,456,789,012" "1,234,567,890,123" "12,345,678,901,234" "123,456,789,012,345" "1,234,567,890,123,456" "12,345,678,901,234,567" "123,456,789,012,345,678" "1,234,567,890,123,456,789" "12,345,678,901,234,567,890" 

The part I’m mostly… fascinated? with is the magic 3.1 near the top which is calculating what the length of the output string with commas added will be (the code of course works backwards). 3.1 Seems To Work™ for the values I’m supplying, but I’m 100.0% sure it’s probably secretly horribly broken on some large inputs (which I’ve not figured out how to test yet).

There are also probably a myriad of other issues I’ve not thought of in terms of coding semantics and style 🙂 (such as the fact that codegolf.SE is ← that way…)

Is there a way to select a value from a column that has commas?

I was wondering if there was a way to select from a column that has separated comma values.

For example, the column has this data: (’16’, ’20’, ’27’, ‘2’, ‘3’)

Is it possible to do something like this:

— get value 16 from table select from table where value = ’16’ or maybe use in? select from table where value in ’16’

How to export CSV without commas in unpopulated cells?

Here’s my problem, I have a form converter which simply rearranges columns. I use a script to paste Values only into another sheet for export and uploading onto another website.

However, when I go to export, it seems to save a bunch of commas after the populated cells. As far as I can tell, these cells are and must be empty.

When I open in Excel, and manually clear contents of the empty cells, the commas disappear.

My question is how do I export without saving these commas, just whats in the populated cells?

Export form. Cells below should be completely empty

Windows preview, showing commas. should not be there

Here’s my export script:

function CopyPasteValues() {   var spreadsheet = SpreadsheetApp.getActive();   spreadsheet.getRange('O3:AS90').activate();   spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Export'), true);   spreadsheet.getRange('A2').activate();   spreadsheet.getRange('Converter!O3:AS90').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);   spreadsheet.getRange('F27').activate(); }; 

Why is Sublime Text 3.2 highlighting commas after values that start with “for” in Python dictionaries?

In the most recent version of Sublime Text (3.2 Build 3200), I have encountered what I think is a syntax highlighting error when writing in Python. Whenever I create a dictionary that has a key/value pair where the variable that represents the value starts with “for”, the comma at the end of the line and all subsequent lines in the dictionary is highlighted pink. For instance:

{     "test": fordgtths, } 

In my editor, the comma in the above text is highlighted pink. When I change the variable so that it does not start with “for”, the highlighting error goes away. Is this in fact an error, or is there something obvious I’m missing? Is there a way to fix it, or do I just need to wait for a patch?

removing commas from a list and just keeping the elements

I have the following list, I want to remove all commas and just be left with the elements of the set.

Tuples[{I, l}, 16]  {{I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I}, {I, I, I, I, I, I,        I, I, I, I, I, I, I, I, I, l}, {I, I, I, I, I, I, I, I, I, I, I, I,        I, I, l, I}, {I, I, I, I, I, I, I, I, I, I, I, I, I, I, l, l}, ....} 

EDIT: So what I want is something like:

{{IIIIIIIIIIIIIIII}, {IIIIIIIIIIIIIIIl}, {IIIIIIIIIIIIIIlI}, {IIIIIIIIIIIIIIll}, ....} 

how to remove colon and comma’s from the array which is like(weight:1.09kg,pieces:112) and add spaces before new line [on hold]

Requirement each record 100 char wide if record size is 20 chars wide append 100-20 =80 spaces before adding a new record . record format is Weight:1.09 kg,Pieces:112,Unit wt:0.9g,Date/time:12/20/2018:12.27.54

and need it to like 1.09 kg,112,0.9g,12/20/2018:12.27.54 and add space before add new line