« first day (980 days earlier)      last day (2323 days later) » 

7:31 AM
Morning all
Love it when everyone at work is on vacation! It's more peaceful than my house :)
 
@Sotos, we can try to change that for you :-)
Keep pinging you every couple of minutes...
 
@A5C1D2H2I1M1N2O1R2T1 I have no speakers on my pc. It does sound a little off the headphones but considering that I will be also napping then I think it should be fine :D
 
8:38 AM
The intersection of these values = intersect(c(1,2,3), c(4,2,1), c(2,2,2), c(1,3,5)) = NULL. But without the last one it will be 2. — Dr. Richard Tennen 10 mins ago
 
@Sotos I missed that comment. I was suspecting OP wanted that, but wanted OP to clarify.
and the post is gone...
 
9:20 AM
So I am debugging a for loop in which I have a variable c (ok, I know it is not a good name). How do I print the value of c in debugger?
when I enter c, it just continues the loop misunderstading the value of c as continue. :|
ok..one way I found out was to execute print(c) in debugger mode.
 
@RonakShah That's what I do (print(c))
 
Ohh..This is language independent problem, even in python I face the same issue.
 
10:19 AM
Close I guess?
 
10:55 AM
Close this, this, this...
 
@A5C1D2H2I1M1N2O1R2T1 Done, done, done and done :p
It's like people know that there is not as much moderation these days so they are posting all their crap Qs
 
Uwe
@A5C1D2H2I1M1N2O1R2T1 voted
 
I'm going through the unanswered questions queue. Like you said, slow day at work....
Managed to get a lot of my own work done today though, instead of sitting through meetings!
^^ interesting....
 
Uwe
This guy has created a benchmark data set with weekly data of 20000 years. LOL
 
@Uwe "... which is rather unlikely to get weekly data from" :-)
 
11:03 AM
@Uwe lol
 
For the past couple of months, I've had to use my Google Maps timeline to remind myself of where I've been each week :-)
@Uwe, I've got to ask: is there a reason for putting the output as code in a blockquote? I've noticed several people doing that recently....
Should this be closed?
 
hahaha
 
 
1 hour later…
Uwe
12:32 PM
@A5C1D2H2I1M1N2O1R2T1 but I don't tell you the colour I want.
@A5C1D2H2I1M1N2O1R2T1 There are two steps: (1) format as code with Ctrl-K (2) format as blockquote with Ctrl-Q. So the output has a fixed font but can be distinguished from code above or below. That's very convenient for a lazybone like me. Credits go to @Jaap. At least, I've seen that in an answer by him.
 
@Uwe, I figured as such for how to do it. I just wanted to know if there's a why other than visual distinction.
Perhaps @Jaap's answers are what I was thinking of.
My personal preference, of course, is soanswer :-)
Perhaps I should write a modified version of the function with a fancy formatting option....
 
Uwe
12:55 PM
@A5C1D2H2I1M1N2O1R2T1 That's a nice tool. I just had a try. However, I find the leading ## make it difficult to cut & paste the posted output again.
 
hello @ all
 
@Uwe, how so? It should be already captured on your clipboard....
@Jaap, ears burning?
 
back from Christmas celebrations
 
@Uwe, the intention is that the answer is commented out (which I think you've figured out), as in my fabulous answer here ;-)
 
Uwe
@A5C1D2H2I1M1N2O1R2T1 Copying from clipboard into an SO post works fine. But I mean if someone else wants to copy the output from an finally posted answer (for whatever reason) then the leading ## have to be removed again. Sorry for not being clear enough.
@A5C1D2H2I1M1N2O1R2T1 I know it. I was the one who upvoted ;-)
 
1:07 PM
@Uwe, Gotcha.
@Uwe Thanks! Any tips for getting rid of my NULLs? I have a feeling I have to do something with match.call, but not sure what....
 
Though I'm not sure why you would want to copy and paste output....
 
1:22 PM
@A5C1D2H2I1M1N2O1R2T1 I started doing that because then people can better distuinguishe between code and output of the code
@Uwe could very well be that I copied that behaviour from somebody else ;-)
 
@A5C1D2H2I1M1N2O1R2T1 I do that. It's just that it clearly separates code from output and is super quick to do. And it looks alright.
 
Uwe
1:36 PM
@A5C1D2H2I1M1N2O1R2T1 Uh, I'm not acquainted enough with the R internals. Perhaps, some of our package writing R gurus might know the trick?
 
2:06 PM
@Axeman So another vote to modify soanswer :-)
 
@A5C1D2H2I1M1N2O1R2T1 not a strong preference
I only have a preference against making the actual code unpastable by using >
 
huh...? So python can take multiple column names for 1 column? I call `list` to get the `names` of the data frame and I get this list(fw_win_to_model)
['username', 'freq', 'n_host', '4624', '4625', '4634', '4648', ('destination', 'n_dest_dIps'), ('service', 'n_dest_ports'), ('sourceport', 'n_sport')]
 
@Sotos It is pandas?
 
yup
type(fw_win_to_model)
<class 'pandas.core.frame.DataFrame'>
I was trying to convert NaNs to 0 and wouldn't let me do it
fw_win_to_model[np.isnan(fw_win_to_model)] = 0 and fw_win_to_model[pd.isnull(fw_win_to_model)] = 0 won't work
 
fw_win_to_model.columns
For columns.
With list(fw_win_to_model) you are trying to convert it to list.
 
2:14 PM
No I just called list to investigate the names
that is where I saw the double names
but yes the .columns is much beter
>>> fw_win_to_model.columns
Index([                    'username',                         'freq',
                             'n_host',                         '4624',
                               '4625',                         '4634',
                               '4648', ('destination', 'n_dest_dIps'),
          ('service', 'n_dest_ports'),      ('sourceport', 'n_sport')],
      dtype='object')
Is there a way to modify it and delete one of the two names? or rename it somehow?
 
This looks like MultiIndex.
Can you show fw_win_to_model.head(). Especially the headers.
 
>>> fw_to_model.head()
                   destination      service   sourceport            username
                   n_dest_dIps n_dest_ports      n_sport
aathanasiou          57.036458    20.968750  1936.083333         aathanasiou
aconstantinides      27.630208     9.541667   633.572917     aconstantinides
administrator        69.828125    21.677083  1899.192708       administrator
ageorgoudis          23.223958     9.270833   483.270833         ageorgoudis
ahadjicharalambous   16.802083     6.755208   428.984375  ahadjicharalambous
So they look like two names indeed
Though I never thought they actually were two different ones.
 
2:33 PM
@A5C1D2H2I1M1N2O1R2T1, This works:
replace_empty_arguments <- function(a) {
  empty_symbols <- vapply(a, function(x) is.symbol(x) && identical("", as.character(x)), 0)
  a[!!empty_symbols] <- 0
  lapply(a, eval)
}

`[.ftable` <- function (inftable, ...) {
  if (!class(inftable) %in% "ftable") stop("input is not an ftable")
  tblatr <- attributes(inftable)[c("row.vars", "col.vars")]

  valslist <- replace_empty_arguments(as.list(match.call()[-(1:2)]))
  x <- sapply(valslist, function(x) identical(x, 0))
  TAB <- as.table(inftable)
        tab2[c("1st", "3rd"), , , ]


                     Age      Child     Adult
                 Survived    No Yes    No Yes
    Class Sex
    1st   Male                0   5   118  57
          Female              0   1     4 140
    3rd   Male               35  13   387  75
          Female             17  14    89  76
There is probably a more formal way though (?)
 
2:47 PM
@Axeman That does seem to work. Want to post it as an answer?
 
@A5C1D2H2I1M1N2O1R2T1 It's mostly your answer
edit and credit is fine
 
OK. I'll do that.
 
👍
 
@Axeman, edited and sent a hat your way :-)
 
cheers
hope it is useful
 
3:00 PM
Very. I still need to spend some more time with match.call, which I had guessed was what I should be looking at, but couldn't quite figure out what to do with :-)
Anyone have any insights on this question. The OP's comment on my answer doesn't really make sense to me. Not sure if I'm overlooking something obvious in their comment.
 
@A5C1D2H2I1M1N2O1R2T1 It's the only thing I could come up with, since list(...) fails but match.call doesn't. It's relatively ok in this case since there aren't any non dots arguments that might complicate things. I presume someone like Hadley or Brodie would have a much better solution.
 
I know @BrodieG is around, and @hadley sometimes pops in here, so we'll see :-)
 
3:35 PM
Not terrible but maybe close?
 
4:27 PM
@A5C1D2H2I1M1N2O1R2T1 If you want to reduce the problem to specifically the match.call or whatever piece I'm happy to look at that. Right now the whole thing is a bit too large to take in the time I have. Is the hacky/informal part how the ... values are recovered?
 
@BrodieG, Hi. The main contribution from @Axeman was the replace_empty_arguments function for dealing with the ... -- so, yes, that's what I was curious about.
I was trying to look for a [.matrix or [.array or something, but I guess I'm going to have to dig deeper than what I was able to get into during my lunch break today.
 
4:45 PM
@A5C1D2H2I1M1N2O1R2T1 Yeah, you'd have to look at the C code. Not having looked at that specific code, but having looked at other, it's pretty common for C code to test for missigness and then if/else on that. Re @Axeman solution I would probably do something similar, though you need to take care about the evaluation frames to make sure you get the expected result in all circumstances.
It's possible that lapply(a, eval) will produce unexpected results if your functions are in packages and someone else uses them from somewhere other than global env.
You can also use substitute(list(...)) in the case where, unlike with array/matrix, your arguments are genuinely unnamed and you only care about their position. substitute is a little simpler.
 
Thanks. I'll play around a little bit and see what manages to fit in my brain :-)
 
5:49 PM
If you can see deleted answers, this answer might be worth your enjoyment.
Actually, I think they must have posted an answer to the wrong question. That's the only thing that I can think of at the moment.
 
6:04 PM
What other Stack Exchange communities do any of you regularly participate in? What's worth checking out now that there are so many of them?
 
I regularly look at Cross Validated, but aren't really actively participating there
 
@Jaap That site's a bit above my qualifications. :-)
The only answers I've been able to provide there relate to visualization of data, which is pretty opinionated.
 
@A5C1D2H2I1M1N2O1R2T1 I have only 8 answers there, the last one from nearly 2 yrs ago
@A5C1D2H2I1M1N2O1R2T1 I go there to find answers, not post them ;-) (with a few exceptions ---^)
 
@Jaap, that's six more than I have, and my last answer is from 2013!
 
@A5C1D2H2I1M1N2O1R2T1 you could try DS as a surrogate ;-)
 
6:20 PM
If I could only get past the name....
 
Actually you probably have to use match.call, not substitute, because substitute will not properly disambiguate the location of symbols if there are nested frames with ... forwarded.
 
7:13 PM
 
@Jaap Agreed.
 
thx, closed now
 
 
1 hour later…
8:25 PM
@BrodieG match.call() is almost always the wrong tool. Do you have a precise specification of the problem?
Ooops, replied to wrong person, I meant @A5C1D2H2I1M1N2O1R2T1 - do you have a precise specification of the problem?
 
oy, got a case of DT[, {lots; of; code}, by=g] and can't find a way to print warnings (if any) at each iteration of the loop so i can figure out where problems are happening
guess i need to dig up a catchWarnings or some such
 
8:44 PM
@hadley He wants to implement an [ indexing method for ftable objects, where one can specify multiple dimensions through ..., like for arrays. But we're uncertain what the "correct" way is to deal with empty arguments, since using list(...) gives an error. So how to deal with calls like mytable[c("1st", "3rd"), , "Child", ]? See the question for the long version.
 
8:57 PM
rlang::dots_list() is the easiest way - I don't think there's a 100% correct way to do this with only base R (without C)
 
9:36 PM
@hadley I'm probably missing something, but doesn't rlang::dot_list evaluate the arguments, which means it can't avoid the missing arg error:
> f_rlang <- function(...) rlang::dots_list(...)
> f_rlang(, 3)
Error in eval_bare(dot$expr, dot$env) :
  argument is missing, with no default
And as far as I know, you can't even avoid this with C because there is no public interface that passes arguments through unevaluated.
So, match.call / substitute seem like the only available tools, at least that I know of, but substitute doesn't work correctly in the nested case.
Seems like the closest (sorry if I'm doing this wrong, not super familiar with rlang) is rlang::exprs, but it seems to have the same issue as substitute:
> f_rlang <- function(...) rlang::exprs(...)
> f_mc <- function(...) match.call()
> f_outer <- function(...) list(rlang=f_rlang(...), match.call=f_mc(...))
> str(f_outer(x, y))
List of 2
 $ rlang     :List of 2
  ..$ : symbol x
  ..$ : symbol y
 $ match.call: language f_mc(..1, ..2)
match.call correctly returns ..1 and ..2, so these can be evaluated in the correct environment with no possibility of ambiguity (e.g. if f_outer used the symbols x and/or y).
Ah, I hadn't seen the .ignore.empty argument for dots_list, although in this case it drops the argument entirely, which wouldn't work. @hadley is there a way to preserve the position of the empty argument?
BTW, looking at source for rlang, @lionel nice workaround for getting the unevaluated arguments. Wouldn't have occurred to me to pull them directly from the function environment instead of passing them through .Call.
 
10:07 PM
Okay, looks like the solution with rlang is:
f_rlang <- function(...) rlang::quos(...)
 
10:37 PM
@BrodieG I'm pretty sure you want them evaluated for this use case. If dots_list() fails with this input, it's a bug in dots_list()
 
11:02 PM
@hadley I can file a bug report if you'd like, but I'm not entirely sure what dots_list is supposed to do when it encounters a missing value that is part of .... Return R_MissingArg? This isn't super useful outside of C as there touching the return value triggers an error.
To recap, the error case is: f_rlang(, 3) (note the missing argument).
I guess you could return a NULL, and add an attribute that indicates whether the NULL is actually a stand in for a missing value.
 

« first day (980 days earlier)      last day (2323 days later) »