问:
Two-Way Repeated Measures ANOVA: Error in lm.fit()... 0 non-na cases (rstatix)
I am trying to run a Two-Way Repeated Measures ANOVA using the R Statix package based on the description from here  however I am running into the subject error with my dataset.  The data consist of 10 replicate biomass measurements recorded at each of 8 Locations across 5 months (10 reps x 8 locations x 5 months = 400 observations).

```<code>head(biomass)
</code>```

However, when I run this:

```<code>library(rstatix)

res.aov <- anova_test(
  data = biomass, dv = Biomass, wid = ID,
  within = c(Location, SampleMonth)
)
</code>```

I get the error:

```<code>Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases
</code>```

I've looked at similar posts here and here that seem to indicate that the error is caused by NA in the lm.

Based on the first post above, I tried to run:

```<code>lm(Biomass~Location:SampleMonth, data =biomass)
</code>```

and I noticed that one Location:SampleMonth value shows an NA coefficient (LocationMPE:SampleMonth10 ).  However, if I remove all the data from this Location and try again, all that happens is that another Location:SampleMonth coefficient becomes NA.  This seems to occur with whatever combination (even just 2) locations.

Am I doing something wrong?

Below is a dput() of my entire dataset:

```<code>biomass <- structure(list(ID = structure(1:400, .Label = c("1", "2", "3",
    "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
    "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
    "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
    "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
    "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
    "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
    "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81",
    "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92",
    "93", "94", "95", "96", "97", "98", "99", "100", "101", "102",
    "103", "104", "105", "106", "107", "108", "109", "110", "111",
    "112", "113", "114", "115", "116", "117", "118", "119", "120",
    "121", "122", "123", "124", "125", "126", "127", "128", "129",
    "130", "131", "132", "133", "134", "135", "136", "137", "138",
    "139", "140", "141", "142", "143", "144", "145", "146", "147",
    "148", "149", "150", "151", "152", "153", "154", "155", "156",
    "157", "158", "159", "160", "161", "162", "163", "164", "165",
    "166", "167", "168", "169", "170", "171", "172", "173", "174",
    "175", "176", "177", "178", "179", "180", "181", "182", "183",
    "184", "185", "186", "187", "188", "189", "190", "191", "192",
    "193", "194", "195", "196", "197", "198", "199", "200", "201",
    "202", "203", "204", "205", "206", "207", "208", "209", "210",
    "211", "212", "213", "214", "215", "216", "217", "218", "219",
    "220", "221", "222", "223", "224", "225", "226", "227", "228",
    "229", "230", "231", "232", "233", "234", "235", "236", "237",
    "238", "239", "240", "241", "242", "243", "244", "245", "246",
    "247", "248", "249", "250", "251", "252", "253", "254", "255",
    "256", "257", "258", "259", "260", "261", "262", "263", "264",
    "265", "266", "267", "268", "269", "270", "271", "272", "273",
    "274", "275", "276", "277", "278", "279", "280", "281", "282",
    "283", "284", "285", "286", "287", "288", "289", "290", "291",
    "292", "293", "294", "295", "296", "297", "298", "299", "300",
    "301", "302", "303", "304", "305", "306", "307", "308", "309",
    "310", "311", "312", "313", "314", "315", "316", "317", "318",
    "319", "320", "321", "322", "323", "324", "325", "326", "327",
    "328", "329", "330", "331", "332", "333", "334", "335", "336",
    "337", "338", "339", "340", "341", "342", "343", "344", "345",
    "346", "347", "348", "349", "350", "351", "352", "353", "354",
    "355", "356", "357", "358", "359", "360", "361", "362", "363",
    "364", "365", "366", "367", "368", "369", "370", "371", "372",
    "373", "374", "375", "376", "377", "378", "379", "380", "381",
    "382", "383", "384", "385", "386", "387", "388", "389", "390",
    "391", "392", "393", "394", "395", "396", "397", "398", "399",
    "400"), class = "factor"), Location = structure(c(6L, 7L, 5L,
    8L, 6L, 6L, 8L, 5L, 3L, 8L, 7L, 7L, 8L, 6L, 8L, 1L, 8L, 4L, 8L,
    8L, 1L, 3L, 6L, 3L, 7L, 3L, 2L, 8L, 6L, 6L, 4L, 3L, 4L, 3L, 6L,
    2L, 2L, 3L, 3L, 7L, 2L, 1L, 4L, 7L, 8L, 6L, 4L, 8L, 7L, 4L, 4L,
    8L, 3L, 5L, 4L, 8L, 5L, 4L, 8L, 3L, 3L, 2L, 7L, 2L, 7L, 4L, 5L,
    3L, 2L, 8L, 4L, 4L, 5L, 1L, 4L, 7L, 7L, 6L, 2L, 7L, 3L, 3L, 4L,
    5L, 7L, 4L, 4L, 1L, 6L, 1L, 3L, 1L, 1L, 1L, 2L, 6L, 1L, 8L, 2L,
    5L, 6L, 5L, 3L, 4L, 4L, 8L, 1L, 1L, 8L, 1L, 5L, 5L, 8L, 8L, 8L,
    6L, 8L, 7L, 8L, 7L, 3L, 5L, 4L, 7L, 5L, 4L, 5L, 1L, 5L, 1L, 6L,
    2L, 8L, 4L, 5L, 4L, 3L, 7L, 8L, 4L, 7L, 7L, 6L, 2L, 2L, 5L, 8L,
    5L, 1L, 2L, 7L, 8L, 7L, 8L, 8L, 1L, 4L, 6L, 4L, 2L, 1L, 7L, 2L,
    8L, 5L, 6L, 1L, 4L, 1L, 8L, 1L, 7L, 3L, 1L, 2L, 2L, 2L, 1L, 6L,
    5L, 2L, 3L, 1L, 5L, 4L, 4L, 4L, 2L, 1L, 5L, 7L, 3L, 7L, 5L, 8L,
    8L, 7L, 2L, 1L, 3L, 5L, 1L, 2L, 3L, 8L, 2L, 1L, 3L, 7L, 7L, 7L,
    7L, 1L, 2L, 4L, 7L, 3L, 8L, 4L, 7L, 2L, 7L, 1L, 8L, 5L, 4L, 7L,
    6L, 8L, 5L, 5L, 3L, 5L, 3L, 1L, 6L, 4L, 6L, 8L, 7L, 6L, 1L, 4L,
    7L, 1L, 2L, 3L, 2L, 1L, 2L, 2L, 6L, 2L, 3L, 2L, 7L, 5L, 4L, 3L,
    3L, 2L, 1L, 1L, 2L, 8L, 6L, 1L, 1L, 7L, 4L, 5L, 5L, 5L, 7L, 6L,
    5L, 8L, 3L, 7L, 5L, 5L, 2L, 1L, 6L, 3L, 6L, 1L, 4L, 2L, 8L, 1L,
    2L, 7L, 7L, 6L, 5L, 2L, 7L, 4L, 7L, 4L, 5L, 5L, 5L, 6L, 5L, 3L,
    1L, 8L, 4L, 1L, 5L, 2L, 4L, 6L, 3L, 3L, 4L, 2L, 5L, 7L, 8L, 5L,
    6L, 1L, 8L, 2L, 1L, 7L, 1L, 5L, 4L, 1L, 6L, 6L, 3L, 3L, 4L, 3L,
    2L, 8L, 5L, 2L, 3L, 6L, 6L, 5L, 2L, 5L, 7L, 6L, 6L, 3L, 8L, 6L,
    7L, 3L, 4L, 2L, 2L, 6L, 5L, 4L, 3L, 3L, 1L, 6L, 1L, 4L, 6L, 2L,
    6L, 4L, 6L, 2L, 7L, 8L, 5L, 4L, 3L, 5L, 1L, 2L, 3L, 6L, 2L, 3L,
    8L, 7L, 6L, 3L, 8L, 6L, 3L, 8L, 6L, 6L, 3L, 4L, 6L), .Label = c("BR",
    "HBY", "MBB", "MCB", "MEB", "MEL", "MPD", "MPE"), class = "factor"),
        SampleMonth = structure(c(1L, 1L, 5L, 3L, 2L, 1L, 1L, 4L,
        2L, 4L, 4L, 2L, 4L, 1L, 5L, 3L, 2L, 1L, 3L, 2L, 1L, 1L, 1L,
        1L, 1L, 1L, 1L, 3L, 5L, 3L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L,
        1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 4L, 3L, 1L, 5L, 3L, 4L, 5L,
        1L, 5L, 5L, 1L, 5L, 5L, 5L, 3L, 1L, 1L, 1L, 1L, 1L, 5L, 4L,
        1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 1L, 1L, 1L, 1L, 1L, 5L, 4L,
        3L, 1L, 5L, 2L, 5L, 2L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 5L, 1L,
        1L, 2L, 1L, 3L, 1L, 1L, 4L, 4L, 5L, 1L, 5L, 3L, 5L, 1L, 1L,
        3L, 4L, 2L, 1L, 4L, 2L, 4L, 1L, 1L, 2L, 5L, 4L, 1L, 2L, 2L,
        1L, 3L, 1L, 1L, 5L, 2L, 4L, 5L, 1L, 1L, 5L, 3L, 2L, 1L, 2L,
        4L, 3L, 5L, 1L, 1L, 3L, 5L, 2L, 5L, 3L, 4L, 1L, 2L, 4L, 4L,
        5L, 5L, 5L, 5L, 3L, 1L, 4L, 2L, 2L, 3L, 2L, 1L, 4L, 2L, 5L,
        4L, 4L, 2L, 2L, 5L, 1L, 2L, 2L, 2L, 4L, 4L, 2L, 2L, 3L, 5L,
        4L, 3L, 2L, 3L, 4L, 2L, 4L, 5L, 5L, 5L, 1L, 3L, 3L, 3L, 3L,
        4L, 3L, 2L, 1L, 2L, 3L, 3L, 4L, 4L, 4L, 2L, 2L, 4L, 4L, 3L,
        2L, 4L, 4L, 5L, 3L, 2L, 1L, 3L, 4L, 5L, 5L, 1L, 1L, 4L, 2L,
        5L, 4L, 2L, 3L, 1L, 2L, 3L, 3L, 2L, 4L, 3L, 3L, 5L, 2L, 4L,
        3L, 3L, 5L, 4L, 4L, 2L, 2L, 2L, 5L, 5L, 5L, 2L, 2L, 3L, 2L,
        4L, 4L, 5L, 4L, 5L, 5L, 4L, 4L, 3L, 4L, 5L, 3L, 2L, 5L, 4L,
        5L, 5L, 3L, 3L, 5L, 3L, 4L, 2L, 2L, 2L, 2L, 2L, 5L, 5L, 2L,
        5L, 5L, 2L, 3L, 4L, 5L, 2L, 4L, 5L, 2L, 2L, 3L, 3L, 4L, 4L,
        2L, 3L, 2L, 3L, 3L, 3L, 5L, 4L, 3L, 3L, 4L, 4L, 3L, 2L, 2L,
        3L, 4L, 2L, 5L, 2L, 2L, 3L, 5L, 2L, 2L, 3L, 2L, 4L, 3L, 5L,
        2L, 2L, 4L, 3L, 5L, 5L, 4L, 3L, 3L, 2L, 4L, 3L, 5L, 4L, 3L,
        2L, 2L, 3L, 2L, 2L, 3L, 4L, 5L, 5L, 5L, 5L, 2L, 5L, 5L, 4L,
        4L, 4L, 5L, 4L, 4L, 4L, 3L, 5L, 3L, 5L, 4L, 5L, 4L, 5L, 4L,
        3L, 4L, 4L, 3L, 3L, 3L, 5L, 5L, 3L, 5L, 2L, 4L, 3L, 4L, 4L,
        3L, 4L), .Label = c("06", "07", "08", "09", "10"), class = "factor"),
        Biomass = c(0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 9.99, 19.99, 36.99, 39.99, 50, 50, 51, 60,
        60, 69.99, 80, 81, 84, 86.99, 89.99, 100, 100, 100, 100.99,
        117, 119.99, 119.99, 119.99, 125, 129.99, 130, 139.99, 140,
        150, 150, 152.99, 159.99, 169.99, 170, 179.99, 184.99, 189.99,
        189.99, 192.99, 199.99, 199.99, 210, 219.99, 219.99, 230,
        230, 235, 248, 250, 269.99, 269.99, 269.99, 276, 279.99,
        280, 282, 289.99, 289.99, 300, 300, 300, 304, 310, 310, 319.99,
        319.99, 326, 329.99, 330, 335.99, 339.99, 339.99, 340, 350,
        350, 360, 362, 369.99, 369.99, 369.99, 375, 379.99, 380,
        383, 384, 390, 390, 399.99, 400, 419.99, 420, 423.99, 429.99,
        430, 430, 430, 435.99, 440, 450, 459.99, 459.99, 465, 469.99,
        479.99, 480, 480, 482, 484, 490, 490, 499.99, 500, 509.99,
        519.99, 529.99, 530, 544.99, 556.99, 559.99, 560, 569.99,
        569.99, 573, 579, 590, 590, 597, 609.99, 609.99, 609.99,
        610, 610, 630, 630, 640, 650, 659.99, 659.99, 659.99, 667,
        670, 680, 680, 680, 690, 700, 702, 709.99, 709.99, 709.99,
        719.99, 719.99, 729.99, 730, 739.99, 740, 744, 745.99, 749.99,
        750, 752, 756.99, 758, 759.99, 759.99, 760, 769.99, 769.99,
        769.99, 780, 789.99, 789.99, 789.99, 790, 794, 809.99, 810,
        810, 810, 819.99, 829.99, 829.99, 830, 840, 840, 850, 869,
        870, 870, 880, 880, 890, 890, 890, 898.99, 900, 900, 909.99,
        910, 919.99, 920, 930, 939.99, 940, 949.99, 950, 950, 959.99,
        960, 970, 979.99, 979.99, 980, 980.99, 989.99, 990, 997.99,
        1000, 1019.99, 1020, 1020, 1029.99, 1030, 1030, 1040, 1049.99,
        1050, 1050, 1059.99, 1069.99, 1080, 1100, 1100, 1120, 1130,
        1130.99, 1139.99, 1153, 1158, 1170, 1170, 1177, 1180, 1180,
        1180, 1180, 1189.99, 1190, 1200, 1219.99, 1220, 1240, 1259.99,
        1259.99, 1279, 1279.99, 1280.99, 1300, 1309.99, 1310, 1316,
        1320, 1330, 1339.99, 1339.99, 1340, 1345, 1359.99, 1360,
        1369, 1370, 1379.99, 1400, 1410, 1420, 1429.99, 1430.99,
        1440, 1440, 1449, 1450, 1459.99, 1468.99, 1470, 1474, 1479.99,
        1490, 1490, 1490, 1499.99, 1510, 1520, 1529.99, 1540, 1560,
        1560, 1570, 1570, 1579.99, 1580, 1580, 1590, 1590, 1594,
        1620, 1630, 1630, 1639.99, 1650, 1650, 1680, 1715, 1719.99,
        1720, 1729.99, 1733, 1770, 1779.99, 1808, 1819.99, 1837,
        1840, 1860, 1900, 1909.99, 1910, 1929.99, 1940, 1954, 2020,
        2040, 2050, 2069.99, 2090, 2100, 2102.99, 2159.99, 2179.99,
        2249.99, 2279.99, 2289.99, 2290, 2334, 2366, 2380, 2399.99,
        2400, 2420, 2450, 2500, 2520, 2550, 2589.99, 2589.99, 2599.99,
        2600, 2620, 2660, 2713, 2739.99, 2830, 2920, 2959.99, 3010,
        3029.99, 3129.99, 3150, 3190, 3250, 3310, 3440, 3490, 3650,
        3740, 3809.99, 3850, 3920, 5799.99, 5898.72, 6680, 6970)), class = c("spec_tbl_df",
    "tbl_df", "tbl", "data.frame"), row.names = c(NA, -400L))
</code>```

答:
First of all, for the lm, you get NAs because you did not specify the main term:

```<code>fit = lm(Biomass ~ SampleMonth*Location,data=biomass)
table(is.na(coefficients(fit)))

FALSE
   40
</code>```

When you do a two way repeated anova, you have an experiment or study that is a repeated measure, something like many patients undergoing a treatment over a period of time etc. In your case, if there is no "repeated measure", or common individuals that underwent the same treatment, then you can use the conventional anova.

If you are interested in effects in time period and sites:

```<code>anova_test(Biomass ~ SampleMonth+Location,data=biomass)
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

       Effect DFn DFd      F        p p<.05   ges
1 SampleMonth   4 388 18.712 4.45e-14     * 0.162
2    Location   7 388  2.969 5.00e-03     * 0.051
</code>```

The above assumes a common mean (or effect) for each month or each location. You can have a more complicated model which test whether there are variations in the Month effect across locations:

```<code>anova_test(Biomass ~ SampleMonth*Location,data=biomass)
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

                Effect DFn DFd      F        p p<.05   ges
1          SampleMonth   4 360 19.507 1.53e-14     * 0.178
2             Location   7 360  3.095 4.00e-03     * 0.057
3 SampleMonth:Location  28 360  1.588 3.20e-02     * 0.110
</code>```

Body:
I am trying to run a Two-Way Repeated Measures ANOVA using the R Statix package based on the description from here  however I am running into the subject error with my dataset.  The data consist of 10 replicate biomass measurements recorded at each of 8 Locations across 5 months (10 reps x 8 locations x 5 months = 400 observations).

head(biomass)

However, when I run this:

library(rstatix)

res.aov <- anova_test(
  data = biomass, dv = Biomass, wid = ID,
  within = c(Location, SampleMonth)
)

I get the error:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases

I've looked at similar posts here and here that seem to indicate that the error is caused by NA in the lm.

Based on the first post above, I tried to run:

lm(Biomass~Location:SampleMonth, data =biomass)

and I noticed that one Location:SampleMonth value shows an NA coefficient (LocationMPE:SampleMonth10 ).  However, if I remove all the data from this Location and try again, all that happens is that another Location:SampleMonth coefficient becomes NA.  This seems to occur with whatever combination (even just 2) locations.

Am I doing something wrong?

Below is a dput() of my entire dataset:

biomass <- structure(list(ID = structure(1:400, .Label = c("1", "2", "3",
    "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
    "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
    "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
    "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
    "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
    "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
    "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81",
    "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92",
    "93", "94", "95", "96", "97", "98", "99", "100", "101", "102",
    "103", "104", "105", "106", "107", "108", "109", "110", "111",
    "112", "113", "114", "115", "116", "117", "118", "119", "120",
    "121", "122", "123", "124", "125", "126", "127", "128", "129",
    "130", "131", "132", "133", "134", "135", "136", "137", "138",
    "139", "140", "141", "142", "143", "144", "145", "146", "147",
    "148", "149", "150", "151", "152", "153", "154", "155", "156",
    "157", "158", "159", "160", "161", "162", "163", "164", "165",
    "166", "167", "168", "169", "170", "171", "172", "173", "174",
    "175", "176", "177", "178", "179", "180", "181", "182", "183",
    "184", "185", "186", "187", "188", "189", "190", "191", "192",
    "193", "194", "195", "196", "197", "198", "199", "200", "201",
    "202", "203", "204", "205", "206", "207", "208", "209", "210",
    "211", "212", "213", "214", "215", "216", "217", "218", "219",
    "220", "221", "222", "223", "224", "225", "226", "227", "228",
    "229", "230", "231", "232", "233", "234", "235", "236", "237",
    "238", "239", "240", "241", "242", "243", "244", "245", "246",
    "247", "248", "249", "250", "251", "252", "253", "254", "255",
    "256", "257", "258", "259", "260", "261", "262", "263", "264",
    "265", "266", "267", "268", "269", "270", "271", "272", "273",
    "274", "275", "276", "277", "278", "279", "280", "281", "282",
    "283", "284", "285", "286", "287", "288", "289", "290", "291",
    "292", "293", "294", "295", "296", "297", "298", "299", "300",
    "301", "302", "303", "304", "305", "306", "307", "308", "309",
    "310", "311", "312", "313", "314", "315", "316", "317", "318",
    "319", "320", "321", "322", "323", "324", "325", "326", "327",
    "328", "329", "330", "331", "332", "333", "334", "335", "336",
    "337", "338", "339", "340", "341", "342", "343", "344", "345",
    "346", "347", "348", "349", "350", "351", "352", "353", "354",
    "355", "356", "357", "358", "359", "360", "361", "362", "363",
    "364", "365", "366", "367", "368", "369", "370", "371", "372",
    "373", "374", "375", "376", "377", "378", "379", "380", "381",
    "382", "383", "384", "385", "386", "387", "388", "389", "390",
    "391", "392", "393", "394", "395", "396", "397", "398", "399",
    "400"), class = "factor"), Location = structure(c(6L, 7L, 5L,
    8L, 6L, 6L, 8L, 5L, 3L, 8L, 7L, 7L, 8L, 6L, 8L, 1L, 8L, 4L, 8L,
    8L, 1L, 3L, 6L, 3L, 7L, 3L, 2L, 8L, 6L, 6L, 4L, 3L, 4L, 3L, 6L,
    2L, 2L, 3L, 3L, 7L, 2L, 1L, 4L, 7L, 8L, 6L, 4L, 8L, 7L, 4L, 4L,
    8L, 3L, 5L, 4L, 8L, 5L, 4L, 8L, 3L, 3L, 2L, 7L, 2L, 7L, 4L, 5L,
    3L, 2L, 8L, 4L, 4L, 5L, 1L, 4L, 7L, 7L, 6L, 2L, 7L, 3L, 3L, 4L,
    5L, 7L, 4L, 4L, 1L, 6L, 1L, 3L, 1L, 1L, 1L, 2L, 6L, 1L, 8L, 2L,
    5L, 6L, 5L, 3L, 4L, 4L, 8L, 1L, 1L, 8L, 1L, 5L, 5L, 8L, 8L, 8L,
    6L, 8L, 7L, 8L, 7L, 3L, 5L, 4L, 7L, 5L, 4L, 5L, 1L, 5L, 1L, 6L,
    2L, 8L, 4L, 5L, 4L, 3L, 7L, 8L, 4L, 7L, 7L, 6L, 2L, 2L, 5L, 8L,
    5L, 1L, 2L, 7L, 8L, 7L, 8L, 8L, 1L, 4L, 6L, 4L, 2L, 1L, 7L, 2L,
    8L, 5L, 6L, 1L, 4L, 1L, 8L, 1L, 7L, 3L, 1L, 2L, 2L, 2L, 1L, 6L,
    5L, 2L, 3L, 1L, 5L, 4L, 4L, 4L, 2L, 1L, 5L, 7L, 3L, 7L, 5L, 8L,
    8L, 7L, 2L, 1L, 3L, 5L, 1L, 2L, 3L, 8L, 2L, 1L, 3L, 7L, 7L, 7L,
    7L, 1L, 2L, 4L, 7L, 3L, 8L, 4L, 7L, 2L, 7L, 1L, 8L, 5L, 4L, 7L,
    6L, 8L, 5L, 5L, 3L, 5L, 3L, 1L, 6L, 4L, 6L, 8L, 7L, 6L, 1L, 4L,
    7L, 1L, 2L, 3L, 2L, 1L, 2L, 2L, 6L, 2L, 3L, 2L, 7L, 5L, 4L, 3L,
    3L, 2L, 1L, 1L, 2L, 8L, 6L, 1L, 1L, 7L, 4L, 5L, 5L, 5L, 7L, 6L,
    5L, 8L, 3L, 7L, 5L, 5L, 2L, 1L, 6L, 3L, 6L, 1L, 4L, 2L, 8L, 1L,
    2L, 7L, 7L, 6L, 5L, 2L, 7L, 4L, 7L, 4L, 5L, 5L, 5L, 6L, 5L, 3L,
    1L, 8L, 4L, 1L, 5L, 2L, 4L, 6L, 3L, 3L, 4L, 2L, 5L, 7L, 8L, 5L,
    6L, 1L, 8L, 2L, 1L, 7L, 1L, 5L, 4L, 1L, 6L, 6L, 3L, 3L, 4L, 3L,
    2L, 8L, 5L, 2L, 3L, 6L, 6L, 5L, 2L, 5L, 7L, 6L, 6L, 3L, 8L, 6L,
    7L, 3L, 4L, 2L, 2L, 6L, 5L, 4L, 3L, 3L, 1L, 6L, 1L, 4L, 6L, 2L,
    6L, 4L, 6L, 2L, 7L, 8L, 5L, 4L, 3L, 5L, 1L, 2L, 3L, 6L, 2L, 3L,
    8L, 7L, 6L, 3L, 8L, 6L, 3L, 8L, 6L, 6L, 3L, 4L, 6L), .Label = c("BR",
    "HBY", "MBB", "MCB", "MEB", "MEL", "MPD", "MPE"), class = "factor"),
        SampleMonth = structure(c(1L, 1L, 5L, 3L, 2L, 1L, 1L, 4L,
        2L, 4L, 4L, 2L, 4L, 1L, 5L, 3L, 2L, 1L, 3L, 2L, 1L, 1L, 1L,
        1L, 1L, 1L, 1L, 3L, 5L, 3L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L,
        1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 4L, 3L, 1L, 5L, 3L, 4L, 5L,
        1L, 5L, 5L, 1L, 5L, 5L, 5L, 3L, 1L, 1L, 1L, 1L, 1L, 5L, 4L,
        1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 1L, 1L, 1L, 1L, 1L, 5L, 4L,
        3L, 1L, 5L, 2L, 5L, 2L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 5L, 1L,
        1L, 2L, 1L, 3L, 1L, 1L, 4L, 4L, 5L, 1L, 5L, 3L, 5L, 1L, 1L,
        3L, 4L, 2L, 1L, 4L, 2L, 4L, 1L, 1L, 2L, 5L, 4L, 1L, 2L, 2L,
        1L, 3L, 1L, 1L, 5L, 2L, 4L, 5L, 1L, 1L, 5L, 3L, 2L, 1L, 2L,
        4L, 3L, 5L, 1L, 1L, 3L, 5L, 2L, 5L, 3L, 4L, 1L, 2L, 4L, 4L,
        5L, 5L, 5L, 5L, 3L, 1L, 4L, 2L, 2L, 3L, 2L, 1L, 4L, 2L, 5L,
        4L, 4L, 2L, 2L, 5L, 1L, 2L, 2L, 2L, 4L, 4L, 2L, 2L, 3L, 5L,
        4L, 3L, 2L, 3L, 4L, 2L, 4L, 5L, 5L, 5L, 1L, 3L, 3L, 3L, 3L,
        4L, 3L, 2L, 1L, 2L, 3L, 3L, 4L, 4L, 4L, 2L, 2L, 4L, 4L, 3L,
        2L, 4L, 4L, 5L, 3L, 2L, 1L, 3L, 4L, 5L, 5L, 1L, 1L, 4L, 2L,
        5L, 4L, 2L, 3L, 1L, 2L, 3L, 3L, 2L, 4L, 3L, 3L, 5L, 2L, 4L,
        3L, 3L, 5L, 4L, 4L, 2L, 2L, 2L, 5L, 5L, 5L, 2L, 2L, 3L, 2L,
        4L, 4L, 5L, 4L, 5L, 5L, 4L, 4L, 3L, 4L, 5L, 3L, 2L, 5L, 4L,
        5L, 5L, 3L, 3L, 5L, 3L, 4L, 2L, 2L, 2L, 2L, 2L, 5L, 5L, 2L,
        5L, 5L, 2L, 3L, 4L, 5L, 2L, 4L, 5L, 2L, 2L, 3L, 3L, 4L, 4L,
        2L, 3L, 2L, 3L, 3L, 3L, 5L, 4L, 3L, 3L, 4L, 4L, 3L, 2L, 2L,
        3L, 4L, 2L, 5L, 2L, 2L, 3L, 5L, 2L, 2L, 3L, 2L, 4L, 3L, 5L,
        2L, 2L, 4L, 3L, 5L, 5L, 4L, 3L, 3L, 2L, 4L, 3L, 5L, 4L, 3L,
        2L, 2L, 3L, 2L, 2L, 3L, 4L, 5L, 5L, 5L, 5L, 2L, 5L, 5L, 4L,
        4L, 4L, 5L, 4L, 4L, 4L, 3L, 5L, 3L, 5L, 4L, 5L, 4L, 5L, 4L,
        3L, 4L, 4L, 3L, 3L, 3L, 5L, 5L, 3L, 5L, 2L, 4L, 3L, 4L, 4L,
        3L, 4L), .Label = c("06", "07", "08", "09", "10"), class = "factor"),
        Biomass = c(0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 9.99, 19.99, 36.99, 39.99, 50, 50, 51, 60,
        60, 69.99, 80, 81, 84, 86.99, 89.99, 100, 100, 100, 100.99,
        117, 119.99, 119.99, 119.99, 125, 129.99, 130, 139.99, 140,
        150, 150, 152.99, 159.99, 169.99, 170, 179.99, 184.99, 189.99,
        189.99, 192.99, 199.99, 199.99, 210, 219.99, 219.99, 230,
        230, 235, 248, 250, 269.99, 269.99, 269.99, 276, 279.99,
        280, 282, 289.99, 289.99, 300, 300, 300, 304, 310, 310, 319.99,
        319.99, 326, 329.99, 330, 335.99, 339.99, 339.99, 340, 350,
        350, 360, 362, 369.99, 369.99, 369.99, 375, 379.99, 380,
        383, 384, 390, 390, 399.99, 400, 419.99, 420, 423.99, 429.99,
        430, 430, 430, 435.99, 440, 450, 459.99, 459.99, 465, 469.99,
        479.99, 480, 480, 482, 484, 490, 490, 499.99, 500, 509.99,
        519.99, 529.99, 530, 544.99, 556.99, 559.99, 560, 569.99,
        569.99, 573, 579, 590, 590, 597, 609.99, 609.99, 609.99,
        610, 610, 630, 630, 640, 650, 659.99, 659.99, 659.99, 667,
        670, 680, 680, 680, 690, 700, 702, 709.99, 709.99, 709.99,
        719.99, 719.99, 729.99, 730, 739.99, 740, 744, 745.99, 749.99,
        750, 752, 756.99, 758, 759.99, 759.99, 760, 769.99, 769.99,
        769.99, 780, 789.99, 789.99, 789.99, 790, 794, 809.99, 810,
        810, 810, 819.99, 829.99, 829.99, 830, 840, 840, 850, 869,
        870, 870, 880, 880, 890, 890, 890, 898.99, 900, 900, 909.99,
        910, 919.99, 920, 930, 939.99, 940, 949.99, 950, 950, 959.99,
        960, 970, 979.99, 979.99, 980, 980.99, 989.99, 990, 997.99,
        1000, 1019.99, 1020, 1020, 1029.99, 1030, 1030, 1040, 1049.99,
        1050, 1050, 1059.99, 1069.99, 1080, 1100, 1100, 1120, 1130,
        1130.99, 1139.99, 1153, 1158, 1170, 1170, 1177, 1180, 1180,
        1180, 1180, 1189.99, 1190, 1200, 1219.99, 1220, 1240, 1259.99,
        1259.99, 1279, 1279.99, 1280.99, 1300, 1309.99, 1310, 1316,
        1320, 1330, 1339.99, 1339.99, 1340, 1345, 1359.99, 1360,
        1369, 1370, 1379.99, 1400, 1410, 1420, 1429.99, 1430.99,
        1440, 1440, 1449, 1450, 1459.99, 1468.99, 1470, 1474, 1479.99,
        1490, 1490, 1490, 1499.99, 1510, 1520, 1529.99, 1540, 1560,
        1560, 1570, 1570, 1579.99, 1580, 1580, 1590, 1590, 1594,
        1620, 1630, 1630, 1639.99, 1650, 1650, 1680, 1715, 1719.99,
        1720, 1729.99, 1733, 1770, 1779.99, 1808, 1819.99, 1837,
        1840, 1860, 1900, 1909.99, 1910, 1929.99, 1940, 1954, 2020,
        2040, 2050, 2069.99, 2090, 2100, 2102.99, 2159.99, 2179.99,
        2249.99, 2279.99, 2289.99, 2290, 2334, 2366, 2380, 2399.99,
        2400, 2420, 2450, 2500, 2520, 2550, 2589.99, 2589.99, 2599.99,
        2600, 2620, 2660, 2713, 2739.99, 2830, 2920, 2959.99, 3010,
        3029.99, 3129.99, 3150, 3190, 3250, 3310, 3440, 3490, 3650,
        3740, 3809.99, 3850, 3920, 5799.99, 5898.72, 6680, 6970)), class = c("spec_tbl_df",
    "tbl_df", "tbl", "data.frame"), row.names = c(NA, -400L))

Body:
First of all, for the lm, you get NAs because you did not specify the main term:

fit = lm(Biomass ~ SampleMonth*Location,data=biomass)
table(is.na(coefficients(fit)))

FALSE
   40

When you do a two way repeated anova, you have an experiment or study that is a repeated measure, something like many patients undergoing a treatment over a period of time etc. In your case, if there is no "repeated measure", or common individuals that underwent the same treatment, then you can use the conventional anova.

If you are interested in effects in time period and sites:

anova_test(Biomass ~ SampleMonth+Location,data=biomass)
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

       Effect DFn DFd      F        p p<.05   ges
1 SampleMonth   4 388 18.712 4.45e-14     * 0.162
2    Location   7 388  2.969 5.00e-03     * 0.051

The above assumes a common mean (or effect) for each month or each location. You can have a more complicated model which test whether there are variations in the Month effect across locations:

anova_test(Biomass ~ SampleMonth*Location,data=biomass)
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

                Effect DFn DFd      F        p p<.05   ges
1          SampleMonth   4 360 19.507 1.53e-14     * 0.178
2             Location   7 360  3.095 4.00e-03     * 0.057
3 SampleMonth:Location  28 360  1.588 3.20e-02     * 0.110


来源: stackexchange

问:
Getting HTTP ERROR 404 with Jenkins
I am getting below error when trying to access jenkins pipeline url. I tried clearing the browser cache, tried different browsers etc but no luck. the same pipeline url works fine for other users but not for me. any ideas why it throwing 404 error for me? many thanks!</p>

```<code>HTTP ERROR 404
Problem accessing /job/jenkins/job/test/. Reason:

    Not Found
Powered by Jetty:// 9.4.z-SNAPSHOT
</code>```

答: I have faced the same issue and identified JIRA and Jenkins are installed on same port 8080. Jenkins service is starting first because of that JIRA was not working. Then I have edited Jenkins.xml file with port 8081 and restarted the services it was working fine.</p>

ContentLicense: CC BY-SA 3.0

Title: Getting HTTP ERROR 404 with Jenkins

Body:
I am getting below error when trying to access jenkins pipeline url. I tried clearing the browser cache, tried different browsers etc but no luck. the same pipeline url works fine for other users but not for me. any ideas why it throwing 404 error for me? many thanks!

HTTP ERROR 404
Problem accessing /job/jenkins/job/test/. Reason:

    Not Found
Powered by Jetty:// 9.4.z-SNAPSHOT

ContentLicense: CC BY-SA 4.0


问:
I uninstalled some Python 2.7 essential files from my Mac, and my OS is now problematic. If I update the software will they be reinstalled?
I am learning Python and accidentally uninstalled some Python 2.7 essential files from my Mac, and began running into some problems. I researched and apparently python 2.7 comes with macOS and is essential for the system. I have important files on my computer and would hate to have to reinstall macOS. I just saw that there is a software update available. If I update the software will these essential files be restored?</p>

答:
Hmm, where did you uninstall from? Let's hope you didn't remove it from your System/Library! See this post here - the discussions/answers may provide some help: How to uninstall Python 2.7 on a Mac OS X 10.6.4?. And yes, @FishingCode could be right - an update may just solve the problem.

Steps you could take:

1) Try updating first!

2) If the update did not work AND your accidental deletions did not affect the system files, then try uninstalling any third-party Python files with:

rm -rf </Library/Frameworks/Python.framework/Versions/VERSION_NUMBER> (replace VERSION_NUMBER with the Python version you want to remove)

OR

If you installed with pip, pip uninstall <Python>

You can also remove the third-party Python 2.7 from the same path (check the same post I referenced above! The accepted answer details a good plan to follow!).

Then, reinstall the usual way (https://www.python.org).

3) Check with the Apple stores/Apple technician.

Overall Recommendations:
I do recommend you install a Python version >= 3! Python 2 support has been deprecated since last year and there are some considerable differences between Python 2 and Python 3.x. You can definitely install the latest version (3.8), too. Hope this helps :)


问:
React hooks how to only execute side effect function only once if I need to update 2 dependency variables
Lets say I have the following component using react hooks

const Component = (props) => {
   [state1, setState1] = useState();
   [state2, setState2] = useState();
   useEffect(()=>{
       // use state1 and state2 as param to fetch data
       ...
   }, [state1, state2])

   onSomethingChange = () => {
       setState1(...);
       setState2(...);
   }

   return (..);
}
```

When onSomethingChange triggers, I thought it would call the side effect function twice since I update 2 different state vars in the same dependency array. And I was going to refactor those 2 vars into 1 object but I thought I would test them as 2 separate vars first.

What I observed is the side effect function only gets executed once even when I update 2 different state vars in the same dependency array, this is what I wanted but I don't know why. Could someone please explain how it works under the bonnet?

答:
React batches state updates under the hood.

That simply means that calling

```<code>setState1(...);
setState2(...);
</code>```

in the same synchronous (!) execution cycle (e.g. in the same function) will NOT trigger two component re-render cycles.

Instead, the component will only re-render once and both state updates will be applied simultaneously.

Not directly related, but also sometimes misunderstood, is when the new state value is available.

Consider this code:

```<code>console.log(name); // prints name state, e.g. 'Doe'
setName('John');
</code>```

console.log(name); // ??? what gets printed? 'John'?

You could think that accessing the name state after setName('John');
 should yield the new value (e.g. 'John') but this is NOT the case.

The new state value is only available in the next component render cycle (which gets scheduled by calling setName()).

Body:
Lets say I have the following component using react hooks

const Component = (props) => {
   [state1, setState1] = useState();
   [state2, setState2] = useState();
   useEffect(()=>{
       // use state1 and state2 as param to fetch data
       ...
   }, [state1, state2])

   onSomethingChange = () => {
       setState1(...);
       setState2(...);
   }

   return (..);
}

When onSomethingChange triggers, I thought it would call the side effect function twice since I update 2 different state vars in the same dependency array. And I was going to refactor those 2 vars into 1 object but I thought I would test them as 2 separate vars first.

What I observed is the side effect function only gets executed once even when I update 2 different state vars in the same dependency array, this is what I wanted but I don't know why. Could someone please explain how it works under the bonnet?

Body:
React batches state updates under the hood.

That simply means that calling

setState1(...);
setState2(...);

in the same synchronous (!) execution cycle (e.g. in the same function) will NOT trigger two component re-render cycles.

Instead, the component will only re-render once and both state updates will be applied simultaneously.

Not directly related, but also sometimes misunderstood, is when the new state value is available.

Consider this code:

console.log(name); // prints name state, e.g. 'Doe'
setName('John');

console.log(name); // ??? what gets printed? 'John'?

You could think that accessing the name state after setName('John');
 should yield the new value (e.g. 'John') but this is NOT the case.

The new state value is only available in the next component render cycle (which gets scheduled by calling setName()).


问:
Issue with oauth2 , can't get access_token when it is created
I've spent nearly 5 hours searching on internet trying to solve this problem and nothing comes up. I want to get my access_token when it is created, save it into a variable, and then store it on db. However, I can't extract the created access_token.

package main

import (
    "fmt"
    "log"
    "net/http"

    oauth2 "gopkg.in/oauth2.v3"
    "gopkg.in/oauth2.v3/models"

    "gopkg.in/oauth2.v3/errors"
    "gopkg.in/oauth2.v3/manage"
    "gopkg.in/oauth2.v3/server"
    "gopkg.in/oauth2.v3/store"
)

func main() {
    manager := manage.NewDefaultManager()

    manager.SetAuthorizeCodeTokenCfg(manage.DefaultAuthorizeCodeTokenCfg)

    manager.MustTokenStorage(store.NewMemoryTokenStore())

    clientStore := store.NewClientStore()
    clientStore.Set("12345", &models.Client{
        ID:     "12345",
        Secret: "12345",
        Domain: "http://localhost:9094",
    })
    manager.MapClientStorage(clientStore)

    srv := server.NewDefaultServer(manager)
    srv.SetAllowGetAccessRequest(true)
    srv.SetClientInfoHandler(server.ClientFormHandler)
    manager.SetRefreshTokenCfg(manage.DefaultRefreshTokenCfg)

    srv.SetInternalErrorHandler(func(err error) (re *errors.Response) {
        log.Println("Internal Error:", err.Error())
        return
    })

    srv.SetResponseErrorHandler(func(re *errors.Response) {
        log.Println("Response Error:", re.Error.Error())
    })

    http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
        srv.HandleTokenRequest(w, r)
    })

    http.HandleFunc("/protected", validateToken(func(w http.ResponseWriter, r *http.Request) {

        w.Write([]byte("Hello, I'm protected"))
    }, srv))

    log.Fatal(http.ListenAndServe(":9099", nil))

}

func validateToken(f http.HandlerFunc, srv *server.Server) http.HandlerFunc {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

        _, err := srv.ValidationBearerToken(r)
        if err != nil {
            http.Error(w, err.Error(), http.StatusBadRequest)
            return
        }
        f.ServeHTTP(w, r)
    })
}
```

I would appreciate any help, since I'm just a trainee programmer and this is still new for me.

Thanks :).

答: Never mind, it's impossible to get the token due the plugin do the job for you.!!!</p>

Body:
I've spent nearly 5 hours searching on internet trying to solve this problem and nothing comes up. I want to get my access_token when it is created, save it into a variable, and then store it on db. However, I can't extract the created access_token.

package main

import (
    "fmt"
    "log"
    "net/http"

    oauth2 "gopkg.in/oauth2.v3"
    "gopkg.in/oauth2.v3/models"

    "gopkg.in/oauth2.v3/errors"
    "gopkg.in/oauth2.v3/manage"
    "gopkg.in/oauth2.v3/server"
    "gopkg.in/oauth2.v3/store"
)

func main() {
    manager := manage.NewDefaultManager()

    manager.SetAuthorizeCodeTokenCfg(manage.DefaultAuthorizeCodeTokenCfg)

    manager.MustTokenStorage(store.NewMemoryTokenStore())

    clientStore := store.NewClientStore()
    clientStore.Set("12345", &models.Client{
        ID:     "12345",
        Secret: "12345",
        Domain: "http://localhost:9094",
    })
    manager.MapClientStorage(clientStore)

    srv := server.NewDefaultServer(manager)
    srv.SetAllowGetAccessRequest(true)
    srv.SetClientInfoHandler(server.ClientFormHandler)
    manager.SetRefreshTokenCfg(manage.DefaultRefreshTokenCfg)

    srv.SetInternalErrorHandler(func(err error) (re *errors.Response) {
        log.Println("Internal Error:", err.Error())
        return
    })

    srv.SetResponseErrorHandler(func(re *errors.Response) {
        log.Println("Response Error:", re.Error.Error())
    })

    http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
        srv.HandleTokenRequest(w, r)
    })

    http.HandleFunc("/protected", validateToken(func(w http.ResponseWriter, r *http.Request) {

        w.Write([]byte("Hello, I'm protected"))
    }, srv))

    log.Fatal(http.ListenAndServe(":9099", nil))

}

func validateToken(f http.HandlerFunc, srv *server.Server) http.HandlerFunc {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

        _, err := srv.ValidationBearerToken(r)
        if err != nil {
            http.Error(w, err.Error(), http.StatusBadRequest)
            return
        }
        f.ServeHTTP(w, r)
    })
}

I would appreciate any help, since I'm just a trainee programmer and this is still new for me.

Thanks :).


问:
Error connecting to mac from visual studio
I have the right IP address although when I go to connect to my mac I get this error message:

An error occurred while generating the SSH keys. Please check that the environment is properly configured. Details: cat: /Users/cbcb/Library/Caches/Xamarin/XMA/Keys/---------------------: No such file or directory

I have tried creating a new admin user, I have remote login enabled, and when I go to the following location above the folder is blanked.

答: Sounds like you may need to redirect that to your default .ssh key location. Mine on my Mac is ~/.ssh/known_hosts. Also blank out your SSH keys please, just for security.


问:
AWS Lambda and S3 - uploaded pdf file is blank
I have a pretty simple function that uploads a PDF file to an AWS S3  (https://codedestine.com/aws-s3-putobject-java/) using AWS Lambda with Amazon
API Gateway.

I try to upload a PDF file which has 2 pages with text. After upload, the PDF file(on AWS S3) has 2 blank pages.

This is the method I use to upload the PDF file on AWS S3.

```<code>public static void uploadFile2(MultipartFile mpFile, String fileName) throws IOException{

    String dirPath = System.getProperty("java.io.tmpdir", "/tmp");
    File file = new File(dirPath  + "/" + fileName);

    OutputStream ops = new FileOutputStream(file);
    ops.write(mpFile.getBytes());

    s3client.putObject("fakebucketname", fileName, file);

}
</code>```

Why the uploaded PDF file is blank?

答:
You're using an output stream as input to the upload request. Just use File, and include content type, for example:</p>

```<code>File file = new File(fileName);
PutObjectRequest request = new PutObjectRequest("bucketname", "keyname", file);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("application/pdf");
request.setMetadata(metadata);
s3Client.putObject(request);
</code>```

Body:
I have a pretty simple function that uploads a PDF file to an AWS S3  (https://codedestine.com/aws-s3-putobject-java/) using AWS Lambda with Amazon
API Gateway.

I try to upload a PDF file which has 2 pages with text. After upload, the PDF file(on AWS S3) has 2 blank pages.

This is the method I use to upload the PDF file on AWS S3.

public static void uploadFile2(MultipartFile mpFile, String fileName) throws IOException{

    String dirPath = System.getProperty("java.io.tmpdir", "/tmp");
    File file = new File(dirPath  + "/" + fileName);

    OutputStream ops = new FileOutputStream(file);
    ops.write(mpFile.getBytes());

    s3client.putObject("fakebucketname", fileName, file);

}

Why the uploaded PDF file is blank?

Body:
You're using an output stream as input to the upload request. Just use File, and include content type, for example:

File file = new File(fileName);
PutObjectRequest request = new PutObjectRequest("bucketname", "keyname", file);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("application/pdf");
request.setMetadata(metadata);
s3Client.putObject(request);


问:
Fixed Row With Grouping in Mind?
I have this data which i want to create a report using a SSRS

The document column is grouped by customer column.
However there's conditions for the report
- Every 10 Rows the report should trigger a page break.
- If the record less than 10, then empty row will be generated until 10 rows then page break trigger.
- If the record more than 10, then only first 10 will be displayed then the rest is on next page.

Here's the sample of result for page 1, page 2, and page 3:

Is there a way to do this ?

答:
Add a new row group "Parent" , click on the group properties, and on the group expressions enter the expression: =Floor((RowNumber(Nothing)-1) / 10)

go to the next tab down, page breaks and click on between each instance of a group.

Title: Fixed Row With Grouping in Mind?


问:
request google speech to text API using android volley
I'm working on an Android Application that record a speech using the mic of the android device, after that i  encode the recorded speech into base64 format. to transform the speech into a text i use google speech cloud api and  android Volley to send request to google Api. the probleme is when i call the methode for requesting i got this error  ==>

E/Volley: [5921] BasicNetwork.performRequest: Unexpected response code 400 for https://speech.googleapis.com/v1/speech:recognize?key={mykey}

Here is My Code :

```<code>    public class SpeechService {

    private String Url ="https://speech.googleapis.com/v1/speech:recognize?key=${mykey}";

        private RequestQueue requestQueue ;
        private AppCompatActivity app ;
        String savedata ;

        public SpeechService(AppCompatActivity app){

            this.app = app ;
            requestQueue = Volley.newRequestQueue(app.getApplicationContext());
        }

    public void getTextFromGSpeech1(String EncodedSpeech){

        JSONObject jsonObject = new JSONObject();
        JSONObject config = new JSONObject() ;
        JSONObject audio = new JSONObject() ;

        try {

            config.put("encoding", MediaRecorder.OutputFormat.AMR_WB);
            config.put("SampleRateHertz","rba9 rba9");
            config.put("languageCode","fr-FR");
            audio.put("content",EncodedSpeech);

            jsonObject.put("audio", audio );
            jsonObject.put("config", config);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        JsonObjectRequest JObjectREQUEST = new JsonObjectRequest(Request.Method.POST , Url  , jsonObject ,new Response.Listener<JSONObject>(){

            @Override
            public void onResponse(JSONObject response) {

                System.out.println("JSON response is  ============> ");
                System.out.println(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                System.out.println("failed ...............;");

            }
        }){

            @Override
            public String getBodyContentType() {
                return "application/json; charset=utf-8";
            }

        };

        requestQueue.add(JObjectREQUEST);

    }
}
</code>```

and the Json object format must be like this

```<code> {   "audio": {
            "content": ""
          }
            ,
          "config": {
            "encoding": "ENCODING_UNSPECIFIED",
            "languageCode": "fr-FR",
            "sampleRateHertz": 1600
          }
        }
</code>```

答: It should be RecognitionConfig.AudioEncoding.AMR_WB, not MediaRecorder.OutputFormat.AMR_WB. Sample rate is also wrong.

Body:
I'm working on an Android Application that record a speech using the mic of the android device, after that i  encode the recorded speech into base64 format. to transform the speech into a text i use google speech cloud api and  android Volley to send request to google Api. the probleme is when i call the methode for requesting i got this error  ==>

E/Volley: [5921] BasicNetwork.performRequest: Unexpected response code 400 for https://speech.googleapis.com/v1/speech:recognize?key={mykey}

Here is My Code :

    public class SpeechService {

    private String Url ="https://speech.googleapis.com/v1/speech:recognize?key=${mykey}";

        private RequestQueue requestQueue ;
        private AppCompatActivity app ;
        String savedata ;

        public SpeechService(AppCompatActivity app){

            this.app = app ;
            requestQueue = Volley.newRequestQueue(app.getApplicationContext());
        }

    public void getTextFromGSpeech1(String EncodedSpeech){

        JSONObject jsonObject = new JSONObject();
        JSONObject config = new JSONObject() ;
        JSONObject audio = new JSONObject() ;

        try {

            config.put("encoding", MediaRecorder.OutputFormat.AMR_WB);
            config.put("SampleRateHertz","rba9 rba9");
            config.put("languageCode","fr-FR");
            audio.put("content",EncodedSpeech);

            jsonObject.put("audio", audio );
            jsonObject.put("config", config);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        JsonObjectRequest JObjectREQUEST = new JsonObjectRequest(Request.Method.POST , Url  , jsonObject ,new Response.Listener<JSONObject>(){

            @Override
            public void onResponse(JSONObject response) {

                System.out.println("JSON response is  ============> ");
                System.out.println(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                System.out.println("failed ...............;");

            }
        }){

            @Override
            public String getBodyContentType() {
                return "application/json; charset=utf-8";
            }

        };

        requestQueue.add(JObjectREQUEST);

    }
}

and the Json object format must be like this

 {   "audio": {
            "content": ""
          }
            ,
          "config": {
            "encoding": "ENCODING_UNSPECIFIED",
            "languageCode": "fr-FR",
            "sampleRateHertz": 1600
          }
        }


问:
Height not setting to the actual height of the div
I have a DIV that slides open to the height of the content, but for some reason on divs that have no content it's calculating the height wrong.

The 2nd blog entry down (Thoma) is a good example when expanded.

http://dririser.co.uk/index.php

The 'data-height' is 108px but it's setting the height of the DIV to 360px. The DIVs with content in work fine, it sets the correct height but seems to come to the wrong calculation on DIVs with no content in.

This is basically the jist of the code.

Set the hight as a value on the div.

```<code>$(".articleSlide").each(function () {
    var current = $(this);
    current.attr("data-height", current.height());
});
</code>```

Set a variable then apply the height.

```<code>$(".showTeamList").toggle(function() {
    var open_height = $(".articleSlide").attr("data-height") + "px";
    $(this).parent().parent().animate({"height": open_height}, "slow" );
 }, function() {
    $(this).parent().parent().animate({"height": "35"}, "slow" );
});
</code>```

答:
height() "Get the current computed height for the first element in the set of matched elements."

it has the correct behavior because the computed height is none. you need to wrap the elements in an absolutely positioned container with overflow:hidden;height:0;

Body:
I have a DIV that slides open to the height of the content, but for some reason on divs that have no content it's calculating the height wrong.

The 2nd blog entry down (Thoma) is a good example when expanded.

http://dririser.co.uk/index.php

The 'data-height' is 108px but it's setting the height of the DIV to 360px. The DIVs with content in work fine, it sets the correct height but seems to come to the wrong calculation on DIVs with no content in.

This is basically the jist of the code.

Set the hight as a value on the div.

$(".articleSlide").each(function () {
    var current = $(this);
    current.attr("data-height", current.height());
});

Set a variable then apply the height.

$(".showTeamList").toggle(function() {
    var open_height = $(".articleSlide").attr("data-height") + "px";
    $(this).parent().parent().animate({"height": open_height}, "slow" );
 }, function() {
    $(this).parent().parent().animate({"height": "35"}, "slow" );
});


问:
Wordpress shortcode name as an Attribute
I was wondering if possible to setup a shortcode and have the name of the shortcode also work as an attribute. How I have mine currently setup is like so

```<code>add_shortcode('tooltip', 'tooltip');
function tooltip( $atts $content = null) {
array(
    'type'      => '',
);
</code>```

So when someone in wordpress uses the shortcode you type in

[tooltip type="fruit"]Item Name[/tooltip]

Although I was wondering is it possible to just use the name of the shortcode as a atts so I can short it a little bit and have it look like this

```<code>[tooltip="fruit"]Item Name[/tooltip]
</code>```

So pretty much cut out the type attribute and use the name of the shortcode tooltip as an attribute instead.

答:
You have to use first item in $atts array, ($atts[0]) when using shortcode tag as attribute.

Working example:

```<code><?php

add_shortcode('tooltip', 'tooltip');

function tooltip(Array $atts = array(), $content = null, $tag = null) {

  $args = shortcode_atts(array( 0 => null ), $atts);
  $args['type'] = trim($args[0], '"=');
  unset($args[0]);

  extract($args);

  // Your code starts here ...
  $output = array(
    '$type'    => $type,
    '$content' => $content
  );

  $output = '```' . print_r($output, true) . '```';

  return $output;
}
</code>```

Please replace everything after // Your code starts here ...

Executing example:

```<code>[tooltip="fruit"]Item Name[/tooltip]
</code>```

will return:

```<code>```Array
(
    [$type] => fruit
    [$content] => Item Name
)
```
</code>```

Body:
I was wondering if possible to setup a shortcode and have the name of the shortcode also work as an attribute. How I have mine currently setup is like so

add_shortcode('tooltip', 'tooltip');
function tooltip( $atts $content = null) {
array(
    'type'      => '',
);

So when someone in wordpress uses the shortcode you type in

[tooltip type="fruit"]Item Name[/tooltip]

Although I was wondering is it possible to just use the name of the shortcode as a atts so I can short it a little bit and have it look like this

[tooltip="fruit"]Item Name[/tooltip]

So pretty much cut out the type attribute and use the name of the shortcode tooltip as an attribute instead.

Body:
You have to use first item in $atts array, ($atts[0]) when using shortcode tag as attribute.

Working example:

<?php

add_shortcode('tooltip', 'tooltip');

function tooltip(Array $atts = array(), $content = null, $tag = null) {

  $args = shortcode_atts(array( 0 => null ), $atts);
  $args['type'] = trim($args[0], '"=');
  unset($args[0]);

  extract($args);

  // Your code starts here ...
  $output = array(
    '$type'    => $type,
    '$content' => $content
  );

  $output = '<pre>' . print_r($output, true) . '</pre>';

  return $output;
}

Please replace everything after // Your code starts here ...

Executing example:

[tooltip="fruit"]Item Name[/tooltip]

will return:

<pre>Array
(
    [$type] => fruit
    [$content] => Item Name
)
</pre>


问:
get count from multiple tables
I have 3 tables with a common 'type_id' column. its a foreign key from Table_type

Table_1 id,type_id,date...
Table_2 id,type_id,date...
Table_3 id,type_id,date...

Table_Type  id, type_name, description

select type_id, count(*) from Table_1 GROUP BY type_id

gives the count from individual table.

i want to know how many times is a particular type used.

```
type_id, count(from 3 tables)
1      , 10
2      , 5
3 .    , 3
```

答:
Get the counts from each table, combine those queries with UNION, and add up the counts.

```<code>SELECT type_id, SUM(count)
FROM (
    SELECT type_id, COUNT(*) AS count
    FROM table_1
    UNION ALL
    SELECT type_id, COUNT(*) AS count
    FROM table_2
    UNION ALL
    SELECT type_id, COUNT(*) AS count
    FROM table_3
) AS x
GROUP BY type_id
</code>```

If there are indexes on the type_id column, this query should be able to take advantage of them. And the UNION processes smaller tables because it combines after the grouping.

Title: get count from multiple tables

Body:
I have 3 tables with a common 'type_id' column. its a foreign key from Table_type

Table_1 id,type_id,date...
Table_2 id,type_id,date...
Table_3 id,type_id,date...

Table_Type  id, type_name, description

select type_id, count(*) from Table_1 GROUP BY type_id

gives the count from individual table.

i want to know how many times is a particular type used.

type_id, count(from 3 tables)
1      , 10
2      , 5
3 .    , 3

Body:
Get the counts from each table, combine those queries with UNION, and add up the counts.

SELECT type_id, SUM(count)
FROM (
    SELECT type_id, COUNT(*) AS count
    FROM table_1
    UNION ALL
    SELECT type_id, COUNT(*) AS count
    FROM table_2
    UNION ALL
    SELECT type_id, COUNT(*) AS count
    FROM table_3
) AS x
GROUP BY type_id

If there are indexes on the type_id column, this query should be able to take advantage of them. And the UNION processes smaller tables because it combines after the grouping.


问:
Get live word count for document in vim
I would like vim to display the total document word count in the status bar (where the current line and character number are displayed). I have come across similar questions on SO, and have tried all the suggestions mentioned here and here --- and none of them had any effect whatsoever on my status bar.

To explicitly name a few, I tried to paste any of the following in my ~/.vimrc (and ofc subsequently restarted vim):

```<code>function! CountNonEmpty()
    let l = 1
    let char_count = 0
    while l <= line("$")
        if len(substitute(getline(l), '\s', '', 'g')) > 3
            let char_count += 1
        endif
        let l += 1
    endwhile
    return char_count
endfunction

function WordCount()
  let s:old_status = v:statusmsg
  exe "silent normal g\<c-g>"
  let s:word_count = str2nr(split(v:statusmsg)[11])
  let v:statusmsg = s:old_status
  return s:word_count
endfunction

" If buffer modified, update any 'Last modified: ' in the first 20 lines.
" 'Last modified: ' can have up to 10 characters before (they are retained).
" Restores cursor and window position using save_cursor variable.
function! LastModified()
  if &modified
    let save_cursor = getpos(".")
    let n = min([15, line("$")])
    keepjumps exe '1,' . n . 's#^\(.\{,10}LOC:\).*#\1' .
          \ ' ' . CountNonEmpty() . '#e'
    keepjumps exe '1,' . n . 's#^\(.\{,10}Word Count:\).*#\1' .
          \ ' ' . WordCount() . '#e'
    call histdel('search', -1)
    call setpos('.', save_cursor)
  endif
endfun
</code>```

OR

```<code>function WordCount()
  let s:old_status = v:statusmsg
  exe "silent normal g\<c-g>"
  let s:word_count = str2nr(split(v:statusmsg)[11])
  let v:statusmsg = s:old_status
  return s:word_count
endfunction
set statusline=wc:%{WordCount()}
</code>```

OR

```<code>function! WordCount()
   let s:old_status = v:statusmsg
   let position = getpos(".")
   exe ":silent normal g\<c-g>"
   let stat = v:statusmsg
   let s:word_count = 0
   if stat != '--No lines in buffer--'
     let s:word_count = str2nr(split(v:statusmsg)[11])
     let v:statusmsg = s:old_status
   end
   call setpos('.', position)
   return s:word_count
endfunction
set statusline=wc:%{WordCount()}
</code>```

OR

```<code>let g:word_count="<unknown>"
fun! WordCount()
    return g:word_count
endfun
fun! UpdateWordCount()
    let s = system("wc -w ".expand("%p"))
    let parts = split(s, ' ')
    if len(parts) > 1
        let g:word_count = parts[0]
    endif
endfun

augroup WordCounter
    au! CursorHold * call UpdateWordCount()
    au! CursorHoldI * call UpdateWordCount()
augroup END

" how eager are you? (default is 4000 ms)
set updatetime=500

" modify as you please...
set statusline=%{WordCount()}\ words
</code>```

or many many more. And as I said there wa no efect. No error message, no visually perceptible change. I guess there may be a common issue which I am missing, but what is it?

答:
Word count in vim-airline

Word count is provided standard by vim-airline for a number of file types, being at the time of writing:
asciidoc, help, mail, markdown, org, rst, tex ,text

If word count is not shown in the vim-airline, more often this is due to an unrecognised file type. For example, at least for now, the compound file type markdown.pandoc is not being recognised by vim-airline for word count. This can easily be remedied by amending the .vimrc as follows:

```<code>let g:airline#extensions#wordcount#filetypes = '\vasciidoc|help|mail|markdown|markdown.pandoc|org|rst|tex|text'
set laststatus=2    " enables vim-airline.
</code>```

The \v statement overrides the default g:airline#extensions#wordcount#filetypes variable. The last line ensures vim-airline is enabled.

In case of doubt, the &filetype of an opened file is returned upon issuing the following command:

```<code>:echo &filetype
</code>```

Here is a meta-example:

Title: Get live word count for document in vim

Body:
I would like vim to display the total document word count in the status bar (where the current line and character number are displayed). I have come across similar questions on SO, and have tried all the suggestions mentioned here and here --- and none of them had any effect whatsoever on my status bar.

To explicitly name a few, I tried to paste any of the following in my ~/.vimrc (and ofc subsequently restarted vim):

function! CountNonEmpty()
    let l = 1
    let char_count = 0
    while l <= line("$")
        if len(substitute(getline(l), '\s', '', 'g')) > 3
            let char_count += 1
        endif
        let l += 1
    endwhile
    return char_count
endfunction

function WordCount()
  let s:old_status = v:statusmsg
  exe "silent normal g\<c-g>"
  let s:word_count = str2nr(split(v:statusmsg)[11])
  let v:statusmsg = s:old_status
  return s:word_count
endfunction

" If buffer modified, update any 'Last modified: ' in the first 20 lines.
" 'Last modified: ' can have up to 10 characters before (they are retained).
" Restores cursor and window position using save_cursor variable.
function! LastModified()
  if &modified
    let save_cursor = getpos(".")
    let n = min([15, line("$")])
    keepjumps exe '1,' . n . 's#^\(.\{,10}LOC:\).*#\1' .
          \ ' ' . CountNonEmpty() . '#e'
    keepjumps exe '1,' . n . 's#^\(.\{,10}Word Count:\).*#\1' .
          \ ' ' . WordCount() . '#e'
    call histdel('search', -1)
    call setpos('.', save_cursor)
  endif
endfun

OR

function WordCount()
  let s:old_status = v:statusmsg
  exe "silent normal g\<c-g>"
  let s:word_count = str2nr(split(v:statusmsg)[11])
  let v:statusmsg = s:old_status
  return s:word_count
endfunction
set statusline=wc:%{WordCount()}

OR

function! WordCount()
   let s:old_status = v:statusmsg
   let position = getpos(".")
   exe ":silent normal g\<c-g>"
   let stat = v:statusmsg
   let s:word_count = 0
   if stat != '--No lines in buffer--'
     let s:word_count = str2nr(split(v:statusmsg)[11])
     let v:statusmsg = s:old_status
   end
   call setpos('.', position)
   return s:word_count
endfunction
set statusline=wc:%{WordCount()}

OR

let g:word_count="<unknown>"
fun! WordCount()
    return g:word_count
endfun
fun! UpdateWordCount()
    let s = system("wc -w ".expand("%p"))
    let parts = split(s, ' ')
    if len(parts) > 1
        let g:word_count = parts[0]
    endif
endfun

augroup WordCounter
    au! CursorHold * call UpdateWordCount()
    au! CursorHoldI * call UpdateWordCount()
augroup END

" how eager are you? (default is 4000 ms)
set updatetime=500

" modify as you please...
set statusline=%{WordCount()}\ words

or many many more. And as I said there wa no efect. No error message, no visually perceptible change. I guess there may be a common issue which I am missing, but what is it?

Body:
Word count in vim-airline

Word count is provided standard by vim-airline for a number of file types, being at the time of writing:
asciidoc, help, mail, markdown, org, rst, tex ,text

If word count is not shown in the vim-airline, more often this is due to an unrecognised file type. For example, at least for now, the compound file type markdown.pandoc is not being recognised by vim-airline for word count. This can easily be remedied by amending the .vimrc as follows:

let g:airline#extensions#wordcount#filetypes = '\vasciidoc|help|mail|markdown|markdown.pandoc|org|rst|tex|text'
set laststatus=2    " enables vim-airline.

The \v statement overrides the default g:airline#extensions#wordcount#filetypes variable. The last line ensures vim-airline is enabled.

In case of doubt, the &filetype of an opened file is returned upon issuing the following command:

:echo &filetype

Here is a meta-example:


问:
R: locating files that their names contain a specific string from a directory and match to my list of wanted files
It's me the newbie again with another messy file and folder situation(thanks to us biologiests): I got this directory containing a huge amount of .txt files (~900,000+), all the files have been previously handed with inconsistent naming format :(

For example, messy files in directory look like these:

```<code>ctrl_S978765_uns_dummy_00_none.txt
ctrl_S978765_3S_Cookie_00_none.txt
S59607_3S_goody_3M_V10.txt
ctrlnuc30-100_S3245678_DMSO_00_none.txt
ctrlRAP_S0846567_3S_Dex_none.txt
S6498432_2S_Fulra_30mM_V100.txt
.....
</code>```

As you see the naming has no reliable consistency. What's important for me is the ID code embedded in them, such as S978765. Now I have got a list (100 ID codes) of these ID codes that I want.

The CSV file containing the list as below, mind you the list does have repetitive ID codes in the row due to different CLnumber value in the second columns:

```<code>ID code  CLnumber
S978765  1
S978765  2
S306223  1
S897458  1
S514486  2
....
</code>```

So I want to achieve below task: find all the messy named files using the code IDs by matching to my list. And copy them into a new directory.

I have thought of use list.files() to get all the .txt files and their names, then I got stuck at the next step at matching the code ID names, I know how to do it with one string, say "S978765", but if I do it one by one, this is almost just like manual digging the folder.

How could I feed the ID code names in column1 as a list and compare/match them with the messy file title names in the directory and then copy them into a new folder?

Many thanks,
ML

答:
This works:

```<code>library(stringr)

# get this via list.files in your actual code
files <- c("ctrl_S978765_uns_dummy_00_none.txt",
           "ctrl_S978765_3S_Cookie_00_none.txt",
           "S59607_3S_goody_3M_V10.txt",
           "ctrlnuc30-100_S3245678_DMSO_00_none.txt",
           "ctrlRAP_S0846567_3S_Dex_none.txt",
           "S6498432_2S_Fulra_30mM_V100.txt")

ids <- data.frame(`ID Code` = c("S978765", "S978765", "S306223", "S897458", "S514486"),
                  CLnumber = c(1, 2, 1, 1, 2),
                  stringsAsFactors = FALSE)

str_subset(files, paste(ids$ID.Code, collapse = "|"))
#> [1] "ctrl_S978765_uns_dummy_00_none.txt" "ctrl_S978765_3S_Cookie_00_none.txt"
</code>```

str_subset takes a character vector and returns elements matching some pattern. In this case, the pattern is "S978765|S978765|S306223|S897458|S514486" (created by using paste), which is a regular expression that matches any of the ID codes separated by |. So we take files and keep only the elements that have a match in ID Code.

There are many other ways to do this, which may or may not be more clear. For example, you could pass ids$ID.Code directly to str_subset instead of constructing a regular expression via paste, but that would throw a warning about object lengths every time, which could get confusing (or cause problems if you get used to ignoring it and then ignore it in a different context where it matters). Another method would be to use purrr and keep, but while that might be a little bit more clear to write, it would be a lot more inefficient since it would mean making multiple passes over the files vector -- not relevant in this context, but possibly very relevant if you suddenly need to do this for hundreds of thousands of files and IDs.

Body:
It's me the newbie again with another messy file and folder situation(thanks to us biologiests): I got this directory containing a huge amount of .txt files (~900,000+), all the files have been previously handed with inconsistent naming format :(

For example, messy files in directory look like these:

ctrl_S978765_uns_dummy_00_none.txt
ctrl_S978765_3S_Cookie_00_none.txt
S59607_3S_goody_3M_V10.txt
ctrlnuc30-100_S3245678_DMSO_00_none.txt
ctrlRAP_S0846567_3S_Dex_none.txt
S6498432_2S_Fulra_30mM_V100.txt
.....

As you see the naming has no reliable consistency. What's important for me is the ID code embedded in them, such as S978765. Now I have got a list (100 ID codes) of these ID codes that I want.

The CSV file containing the list as below, mind you the list does have repetitive ID codes in the row due to different CLnumber value in the second columns:

ID code  CLnumber
S978765  1
S978765  2
S306223  1
S897458  1
S514486  2
....

So I want to achieve below task: find all the messy named files using the code IDs by matching to my list. And copy them into a new directory.

I have thought of use list.files() to get all the .txt files and their names, then I got stuck at the next step at matching the code ID names, I know how to do it with one string, say "S978765", but if I do it one by one, this is almost just like manual digging the folder.

How could I feed the ID code names in column1 as a list and compare/match them with the messy file title names in the directory and then copy them into a new folder?

Many thanks,
ML

Body:
This works:

library(stringr)

# get this via list.files in your actual code
files <- c("ctrl_S978765_uns_dummy_00_none.txt",
           "ctrl_S978765_3S_Cookie_00_none.txt",
           "S59607_3S_goody_3M_V10.txt",
           "ctrlnuc30-100_S3245678_DMSO_00_none.txt",
           "ctrlRAP_S0846567_3S_Dex_none.txt",
           "S6498432_2S_Fulra_30mM_V100.txt")

ids <- data.frame(`ID Code` = c("S978765", "S978765", "S306223", "S897458", "S514486"),
                  CLnumber = c(1, 2, 1, 1, 2),
                  stringsAsFactors = FALSE)

str_subset(files, paste(ids$ID.Code, collapse = "|"))
#> [1] "ctrl_S978765_uns_dummy_00_none.txt" "ctrl_S978765_3S_Cookie_00_none.txt"

str_subset takes a character vector and returns elements matching some pattern. In this case, the pattern is "S978765|S978765|S306223|S897458|S514486" (created by using paste), which is a regular expression that matches any of the ID codes separated by |. So we take files and keep only the elements that have a match in ID Code.

There are many other ways to do this, which may or may not be more clear. For example, you could pass ids$ID.Code directly to str_subset instead of constructing a regular expression via paste, but that would throw a warning about object lengths every time, which could get confusing (or cause problems if you get used to ignoring it and then ignore it in a different context where it matters). Another method would be to use purrr and keep, but while that might be a little bit more clear to write, it would be a lot more inefficient since it would mean making multiple passes over the files vector -- not relevant in this context, but possibly very relevant if you suddenly need to do this for hundreds of thousands of files and IDs.


问:
Memory Leak warning while addSubView to Current ViewController
I get memory leak warning when I addsubView to Current ViewController....This is my code..

```<code>     NoOfGolferViewController *objNoOfGolferViewController = [[NoOfGolferViewController alloc]initWithNibName:@"NoOfGolferViewController" bundle:nil];
     [objNoOfGolferViewController setParent:self];
     [objNoOfGolferViewController.view setFrame:CGRectMake(15, 110, 290, 330)];
     [self.view addSubview:objNoOfGolferViewController.view];
</code>```

and when I release object

```<code>      [objNoOfGolferViewController release];
</code>```

Application get crashed by giving EXE_BAD_ACCESS message.

How can I solve this memory leak warning?

Thanks in advance..

答: You need to keep your objNoOfGolferViewController object alive as long as its view is visible or used in current controller. The best solution it seems is to make it an instance variable of your current class and release objNoOfGolferViewController in its dealloc method

Body:
I get memory leak warning when I addsubView to Current ViewController....This is my code..

     NoOfGolferViewController *objNoOfGolferViewController = [[NoOfGolferViewController alloc]initWithNibName:@"NoOfGolferViewController" bundle:nil];
     [objNoOfGolferViewController setParent:self];
     [objNoOfGolferViewController.view setFrame:CGRectMake(15, 110, 290, 330)];
     [self.view addSubview:objNoOfGolferViewController.view];

and when I release object

      [objNoOfGolferViewController release];

Application get crashed by giving EXE_BAD_ACCESS message.

How can I solve this memory leak warning?

Thanks in advance..


问:
Can you call a module from a userform whose variable is declared from a combo box?
I created a userform sub that will allow the user to choose from the open workbook to use as the reference workbook using a combo box.  My current script is returning an error that workbooks(wb) is not defined - I assume this is because the variable is defined in two different modules and the combo box is not in the module being called. Ideally would like to use the userform below

```<code>Private Sub Go_Click()

 If ComboBox1.ListIndex = -1 Then
        MsgBox "Please select a workbook name and try again"
        Exit Sub
    End If

  Dim wb As Variant

  wb = ComboBox1.List(ComboBox1.ListIndex)

  Call GenerateReportUserForm

End Sub
</code>```

To call this sub:

```<code>Sub newMacro()

Dim copyNames As Range, pasteNames As Range, copyAmounts As Range, pasteAmounts As Range, copyDates As Range, pasteDates As Range, _
copyPayment As Range, pastePayment As Range

'   For cheques only

Set copyNames = Workbooks(wb).Worksheets(2).Columns("F")
Set copyAmounts = Workbooks(wb).Worksheets(2).Columns("AR")
Set copyDates = Workbooks(wb).Worksheets(2).Columns("AI")
Set copyPayment = Workbooks(wb).Worksheets(2).Columns("AJ")

Set pasteNames = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("A")
Set pasteAmounts = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("C")
Set pasteDates = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("D")
Set pastePayment = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("E")

copyNames.Copy Destination:=pasteNames
copyAmounts.Copy Destination:=pasteAmounts
copyDates.Copy Destination:=pasteDates
copyPayment.Copy Destination:=pastePayment

End sub
</code>```

Thanks!

答:
wb clearly wants to be a String representing the name of a workbook. Declare it as such.

```<code>Dim wbName As String
wbName = ComboBox1.List(ComboBox1.ListIndex)
</code>```

Side note, name your controls. AvailableFilesBox tells so much more than ComboBox1.

Now, what you want is to pass this variable as an argument; do not use a global variable unless you absolutely MUST.

```<code>Call GenerateReportUserForm
</code>```

Not sure what this is supposed to be doing, but it's not calling newMacro. If you want to make it call newMacro, then change it to this:

```<code>NewMacro wbName
</code>```

Or if you really really want to keep that redundant and distracting Call keyword:

```<code>Call NewMacro(wbName)
</code>```

Note: give that macro a meaningful name that describes what the macro does. "new macro" might be clear now, but not so much once there are 4-5 newer macros in that project - and newMacro2 is NOT an option!

Now, in order to pass wbName as an argument, the procedure needs to declare that it takes a parameter - like this:

```<code>Public Sub NewMacro(ByVal wbName As String)
</code>```

Inside that procedure scope, you don't need to constantly dereference the Workbook object. Do it once, store the object reference into a local variable, then use that variable:

```<code>Dim wb As Workbook
Set wb = Workbooks(wbName)
</code>```

Turns out, that macro doesn't really care for the workbook's name; what it really actually wants is a Workbook object. So, let's make it the caller's responsibility to provide a Workbook.

First we change the signature to take a Workbook parameter:

```<code>Public Sub NewMacro(ByVal wb As Workbook)
</code>```

Then we change the form code to supply it:

```<code>Dim wb As Workbook
Set wb = Workbooks(ComboBox1.List(ComboBox1.ListIndex))

NewMacro wb ' or: Call NewMacro(wb)
</code>```

Remember to always put Option Explicit at the top of every module; Rubberduck can help you find & fix this, and other issues in your code.

Body:
I created a userform sub that will allow the user to choose from the open workbook to use as the reference workbook using a combo box.  My current script is returning an error that workbooks(wb) is not defined - I assume this is because the variable is defined in two different modules and the combo box is not in the module being called. Ideally would like to use the userform below

Private Sub Go_Click()

 If ComboBox1.ListIndex = -1 Then
        MsgBox "Please select a workbook name and try again"
        Exit Sub
    End If

  Dim wb As Variant

  wb = ComboBox1.List(ComboBox1.ListIndex)

  Call GenerateReportUserForm

End Sub

To call this sub:

Sub newMacro()

Dim copyNames As Range, pasteNames As Range, copyAmounts As Range, pasteAmounts As Range, copyDates As Range, pasteDates As Range, _
copyPayment As Range, pastePayment As Range

'   For cheques only

Set copyNames = Workbooks(wb).Worksheets(2).Columns("F")
Set copyAmounts = Workbooks(wb).Worksheets(2).Columns("AR")
Set copyDates = Workbooks(wb).Worksheets(2).Columns("AI")
Set copyPayment = Workbooks(wb).Worksheets(2).Columns("AJ")

Set pasteNames = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("A")
Set pasteAmounts = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("C")
Set pasteDates = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("D")
Set pastePayment = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("E")

copyNames.Copy Destination:=pasteNames
copyAmounts.Copy Destination:=pasteAmounts
copyDates.Copy Destination:=pasteDates
copyPayment.Copy Destination:=pastePayment

End sub

Thanks!

Body:
wb clearly wants to be a String representing the name of a workbook. Declare it as such.

Dim wbName As String
wbName = ComboBox1.List(ComboBox1.ListIndex)

Side note, name your controls. AvailableFilesBox tells so much more than ComboBox1.

Now, what you want is to pass this variable as an argument; do not use a global variable unless you absolutely MUST.

Call GenerateReportUserForm

Not sure what this is supposed to be doing, but it's not calling newMacro. If you want to make it call newMacro, then change it to this:

NewMacro wbName

Or if you really really want to keep that redundant and distracting Call keyword:

Call NewMacro(wbName)

Note: give that macro a meaningful name that describes what the macro does. "new macro" might be clear now, but not so much once there are 4-5 newer macros in that project - and newMacro2 is NOT an option!

Now, in order to pass wbName as an argument, the procedure needs to declare that it takes a parameter - like this:

Public Sub NewMacro(ByVal wbName As String)

Inside that procedure scope, you don't need to constantly dereference the Workbook object. Do it once, store the object reference into a local variable, then use that variable:

Dim wb As Workbook
Set wb = Workbooks(wbName)

Turns out, that macro doesn't really care for the workbook's name; what it really actually wants is a Workbook object. So, let's make it the caller's responsibility to provide a Workbook.

First we change the signature to take a Workbook parameter:

Public Sub NewMacro(ByVal wb As Workbook)

Then we change the form code to supply it:

Dim wb As Workbook
Set wb = Workbooks(ComboBox1.List(ComboBox1.ListIndex))

NewMacro wb ' or: Call NewMacro(wb)

Remember to always put Option Explicit at the top of every module; Rubberduck can help you find & fix this, and other issues in your code.


问:
AKS RBAC - Rolebinding has no effect
I'm setting up RBAC in my AKS cluster which is integrated with Azure AD following the instructions here. I have created an AD group in my AAD tenant, added a user to it. Then the group is assigned "Cluster User role" in the AKS cluster as per the instructions. Created a Role and Rolebinding as shown below:

Role:

```<code>apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: development
  name: restricted-role
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
</code>```

RoleBinding:

```<code>apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: development
subjects:
- kind: Group
  name: 308f50cb-e05a-4340-99d4-xxxxxxxb
  apiGroup: rbac.authorization.k8s.io
  namespace: development
roleRef:
  kind: Role
  name: restricted-role
  apiGroup: rbac.authorization.k8s.io
</code>```

I then tried login using the new user credentials:

```<code>az login --username kubeuser@xxx.onmicrosoft.com --password xxxx

az aks get-credentials --name mycluster --resource-group myrg --overwrite-existing
</code>```

As per the documentation, I should be only allowed to do kubectl get pods on the development namespace. However, using this new user credentials, I see that I can do kubectl get pods --all-namespaces, kubectl get svc --all-namespaces etc. and view the results, as if the Rolebinding does not have any impact at all. I also have verified by checking that my cluster has

"enableRBAC": true

Can someone please tell me what is wrong with this configuration?

答:
Using the command:

```<code>az aks show -g <rg> -n <clusterName> --query aadProfile
</code>```

you can confirm if the cluster has Azure Active Directory enabled. If so, the kubeconfig file you get from the following command:

```<code>az aks get-credentials -g <rg_name> -n <aks_name>
</code>```

should look like:

```<code>user:
  auth-provider:
    config:
      apiserver-id: <appserverid>
      client-id: <clientid>
      environment: AzurePublicCloud
      tenant-id: <tenant>
    name: azure
</code>```

Title: AKS RBAC - Rolebinding has no effect

Body:
I'm setting up RBAC in my AKS cluster which is integrated with Azure AD following the instructions here. I have created an AD group in my AAD tenant, added a user to it. Then the group is assigned "Cluster User role" in the AKS cluster as per the instructions. Created a Role and Rolebinding as shown below:

Role:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: development
  name: restricted-role
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]

RoleBinding:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: development
subjects:
- kind: Group
  name: 308f50cb-e05a-4340-99d4-xxxxxxxb
  apiGroup: rbac.authorization.k8s.io
  namespace: development
roleRef:
  kind: Role
  name: restricted-role
  apiGroup: rbac.authorization.k8s.io

I then tried login using the new user credentials:

az login --username kubeuser@xxx.onmicrosoft.com --password xxxx

az aks get-credentials --name mycluster --resource-group myrg --overwrite-existing

As per the documentation, I should be only allowed to do kubectl get pods on the development namespace. However, using this new user credentials, I see that I can do kubectl get pods --all-namespaces, kubectl get svc --all-namespaces etc. and view the results, as if the Rolebinding does not have any impact at all. I also have verified by checking that my cluster has

"enableRBAC": true

Can someone please tell me what is wrong with this configuration?

Body:
Using the command:

az aks show -g <rg> -n <clusterName> --query aadProfile

you can confirm if the cluster has Azure Active Directory enabled. If so, the kubeconfig file you get from the following command:

az aks get-credentials -g <rg_name> -n <aks_name>

should look like:

user:
  auth-provider:
    config:
      apiserver-id: <appserverid>
      client-id: <clientid>
      environment: AzurePublicCloud
      tenant-id: <tenant>
    name: azure


问:
Flink 1.9 : Standalone Cluster : Failed to transfer file from TaskExecutor id : `AskTimeoutException`
Background

Trying to create Apache Flink Standalone cluster.

Environment : AWS

Job Manager : 1

Task Manager : 2

Config :

```<code>FLINK_PLUGINS_DIR                       :   /usr/local/flink-1.9.1/plugins
io.tmp.dirs                             :   /tmp/flink
jobmanager.execution.failover-strategy  :   region
jobmanager.heap.size                    :   1024m
jobmanager.rpc.address                  :   job manager ip
jobmanager.rpc.port                     :   6123
jobstore.cache-size                     :   52428800
jobstore.expiration-time                :   3600
parallelism.default                     :   4
slot.idle.timeout                       :   50000
slot.request.timeout                    :   300000
task.cancellation.interval              :   30000
task.cancellation.timeout               :   180000
task.cancellation.timers.timeout        :   7500
taskmanager.exit-on-fatal-akka-error    :   false
taskmanager.heap.size                   :   1024m
taskmanager.network.bind-policy         :   "ip"
taskmanager.numberOfTaskSlots           :   2
taskmanager.registration.initial-backoff:   500ms
taskmanager.registration.timeout        :   5min
taskmanager.rpc.port                    :   50100-50200
web.tmpdir                              :   /tmp/flink-web-74cce811-17c0-411e-9d11-6d91edd2e9b0
</code>```

Instance Type : t2 medium (2 CPUs 4 GB Memory)

Security Group ports opened : 6123, 8081, 50100 - 50200

OS : CentOS Linux release 7.6.1810 (Core)

Java :

```<code>openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
</code>```

Cluster is up and running properly

```<code>org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - http://ip:8081 was granted leadership with leaderSessionID=00000000-0000-0000-0000-000000000000
org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - Web frontend listening at http:/ip:8081.
org.apache.flink.runtime.rpc.akka.AkkaRpcService              - Starting RPC endpoint for org.apache.flink.runtime.resourcemanager.StandaloneResourceManager at akka://flink/user/resourcemanager .
org.apache.flink.runtime.rpc.akka.AkkaRpcService              - Starting RPC endpoint for org.apache.flink.runtime.dispatcher.StandaloneDispatcher at akka://flink/user/dispatcher .
org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - ResourceManager akka.tcp://flink@ip:6123/user/resourcemanager was granted leadership with fencing token 00000000000000000000000000000000
org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerImpl  - Starting the SlotManager.
org.apache.flink.runtime.dispatcher.StandaloneDispatcher      - Dispatcher akka.tcp://flink@ip:6123/user/dispatcher was granted leadership with fencing token 00000000-0000-0000-0000-000000000000
org.apache.flink.runtime.dispatcher.StandaloneDispatcher      - Recovering all persisted jobs.
org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - Registering TaskManager with ResourceID f2c7f664378b40ce44463713ae98e1c4 (akka.tcp://flink@TaskManager1Ip:38566/user/taskmanager_0) at ResourceManager
org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - Registering TaskManager with ResourceID 354a785f637751fb3b034618a47480ed (akka.tcp://flink@TaskManager2Ip:34400/user/taskmanager_0) at ResourceManager
</code>```

UI shows all the cluster details

Problem

The task submission does not work

```<code>java.util.concurrent.CompletionException: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://flink/user/resourcemanager#-1545644127]] after [10000 ms]. Message of type [org.apache.flink.runtime.rpc.messages.LocalFencedMessage]. A typical reason for `AskTimeoutException` is that the recipient actor didn'
t send a reply.
        at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
        at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
        at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
        at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
        at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
        at org.apache.flink.runtime.concurrent.FutureUtils$1.onComplete(FutureUtils.java:871)
        at akka.dispatch.OnComplete.internal(Future.scala:263)
        at akka.dispatch.OnComplete.internal(Future.scala:261)
        at akka.dispatch.japi$CallbackBridge.apply(Future.scala:191)
        at akka.dispatch.japi$CallbackBridge.apply(Future.scala:188)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36)
        at org.apache.flink.runtime.concurrent.Executors$DirectExecutionContext.execute(Executors.java:74)
        at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:44)
        at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:252)
        at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:644)
        at akka.actor.Scheduler$$anon$4.run(Scheduler.scala:205)
        at scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Future.scala:601)
        at scala.concurrent.BatchingExecutor$class.execute(BatchingExecutor.scala:109)
        at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:599)
        at akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(LightArrayRevolverScheduler.scala:328)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.executeBucket$1(LightArrayRevolverScheduler.scala:279)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRevolverScheduler.scala:283)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolverScheduler.scala:235)
        at java.lang.Thread.run(Thread.java:748)
Caused by: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://flink/user/resourcemanager#-1545644127]] after [10000 ms]. Message of type [org.apache.flink.runtime.rpc.messages.LocalFencedMessage]. A typical reason for `AskTimeoutException` is that the recipient actor didn't send a reply.
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:648)
        ... 9 more
2020-02-04 23:25:16,125 ERROR org.apache.flink.runtime.rest.handler.taskmanager.TaskManagerLogFileHandler  - Unhandled exception.
akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://flink/user/resourcemanager#-1545644127]] after [10000 ms]. Message of type [org.apache.flink.runtime.rpc.messages.LocalFencedMessage]. A typical reason for `AskTimeoutException` is that the recipient actor didn't send a reply.
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:648)
        at akka.actor.Scheduler$$anon$4.run(Scheduler.scala:205)
        at scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Future.scala:601)
        at scala.concurrent.BatchingExecutor$class.execute(BatchingExecutor.scala:109)
        at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:599)
        at akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(LightArrayRevolverScheduler.scala:328)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.executeBucket$1(LightArrayRevolverScheduler.scala:279)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRevolverScheduler.scala:283)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolverScheduler.scala:235)
        at java.lang.Thread.run(Thread.java:748)
</code>```

Can somebody  throw some light on this ? Is it problem related to ports / firewall or some setting is messed up ?

答: The issue was with security group port permissions. When opened entire range from 0 - 65565, everything started working. Still this is not good enough for production system so eventually for Job workers in the flink-conf.yaml  config file, the key taskmanager.data.port was assigned a particular port and that did the trick. This way the task managers could be configured to listen to a particular port within the range.

Body:
Background

Trying to create Apache Flink Standalone cluster.

Environment : AWS

Job Manager : 1

Task Manager : 2

Config :

FLINK_PLUGINS_DIR                       :   /usr/local/flink-1.9.1/plugins
io.tmp.dirs                             :   /tmp/flink
jobmanager.execution.failover-strategy  :   region
jobmanager.heap.size                    :   1024m
jobmanager.rpc.address                  :   job manager ip
jobmanager.rpc.port                     :   6123
jobstore.cache-size                     :   52428800
jobstore.expiration-time                :   3600
parallelism.default                     :   4
slot.idle.timeout                       :   50000
slot.request.timeout                    :   300000
task.cancellation.interval              :   30000
task.cancellation.timeout               :   180000
task.cancellation.timers.timeout        :   7500
taskmanager.exit-on-fatal-akka-error    :   false
taskmanager.heap.size                   :   1024m
taskmanager.network.bind-policy         :   "ip"
taskmanager.numberOfTaskSlots           :   2
taskmanager.registration.initial-backoff:   500ms
taskmanager.registration.timeout        :   5min
taskmanager.rpc.port                    :   50100-50200
web.tmpdir                              :   /tmp/flink-web-74cce811-17c0-411e-9d11-6d91edd2e9b0

Instance Type : t2 medium (2 CPUs 4 GB Memory)

Security Group ports opened : 6123, 8081, 50100 - 50200

OS : CentOS Linux release 7.6.1810 (Core)

Java :

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Cluster is up and running properly

org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - http://ip:8081 was granted leadership with leaderSessionID=00000000-0000-0000-0000-000000000000
org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - Web frontend listening at http:/ip:8081.
org.apache.flink.runtime.rpc.akka.AkkaRpcService              - Starting RPC endpoint for org.apache.flink.runtime.resourcemanager.StandaloneResourceManager at akka://flink/user/resourcemanager .
org.apache.flink.runtime.rpc.akka.AkkaRpcService              - Starting RPC endpoint for org.apache.flink.runtime.dispatcher.StandaloneDispatcher at akka://flink/user/dispatcher .
org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - ResourceManager akka.tcp://flink@ip:6123/user/resourcemanager was granted leadership with fencing token 00000000000000000000000000000000
org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerImpl  - Starting the SlotManager.
org.apache.flink.runtime.dispatcher.StandaloneDispatcher      - Dispatcher akka.tcp://flink@ip:6123/user/dispatcher was granted leadership with fencing token 00000000-0000-0000-0000-000000000000
org.apache.flink.runtime.dispatcher.StandaloneDispatcher      - Recovering all persisted jobs.
org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - Registering TaskManager with ResourceID f2c7f664378b40ce44463713ae98e1c4 (akka.tcp://flink@TaskManager1Ip:38566/user/taskmanager_0) at ResourceManager
org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - Registering TaskManager with ResourceID 354a785f637751fb3b034618a47480ed (akka.tcp://flink@TaskManager2Ip:34400/user/taskmanager_0) at ResourceManager

UI shows all the cluster details

Problem

The task submission does not work

java.util.concurrent.CompletionException: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://flink/user/resourcemanager#-1545644127]] after [10000 ms]. Message of type [org.apache.flink.runtime.rpc.messages.LocalFencedMessage]. A typical reason for `AskTimeoutException` is that the recipient actor didn'
t send a reply.
        at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
        at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
        at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
        at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
        at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
        at org.apache.flink.runtime.concurrent.FutureUtils$1.onComplete(FutureUtils.java:871)
        at akka.dispatch.OnComplete.internal(Future.scala:263)
        at akka.dispatch.OnComplete.internal(Future.scala:261)
        at akka.dispatch.japi$CallbackBridge.apply(Future.scala:191)
        at akka.dispatch.japi$CallbackBridge.apply(Future.scala:188)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36)
        at org.apache.flink.runtime.concurrent.Executors$DirectExecutionContext.execute(Executors.java:74)
        at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:44)
        at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:252)
        at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:644)
        at akka.actor.Scheduler$$anon$4.run(Scheduler.scala:205)
        at scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Future.scala:601)
        at scala.concurrent.BatchingExecutor$class.execute(BatchingExecutor.scala:109)
        at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:599)
        at akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(LightArrayRevolverScheduler.scala:328)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.executeBucket$1(LightArrayRevolverScheduler.scala:279)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRevolverScheduler.scala:283)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolverScheduler.scala:235)
        at java.lang.Thread.run(Thread.java:748)
Caused by: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://flink/user/resourcemanager#-1545644127]] after [10000 ms]. Message of type [org.apache.flink.runtime.rpc.messages.LocalFencedMessage]. A typical reason for `AskTimeoutException` is that the recipient actor didn't send a reply.
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:648)
        ... 9 more
2020-02-04 23:25:16,125 ERROR org.apache.flink.runtime.rest.handler.taskmanager.TaskManagerLogFileHandler  - Unhandled exception.
akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://flink/user/resourcemanager#-1545644127]] after [10000 ms]. Message of type [org.apache.flink.runtime.rpc.messages.LocalFencedMessage]. A typical reason for `AskTimeoutException` is that the recipient actor didn't send a reply.
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$2.apply(AskSupport.scala:635)
        at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:648)
        at akka.actor.Scheduler$$anon$4.run(Scheduler.scala:205)
        at scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Future.scala:601)
        at scala.concurrent.BatchingExecutor$class.execute(BatchingExecutor.scala:109)
        at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:599)
        at akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(LightArrayRevolverScheduler.scala:328)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.executeBucket$1(LightArrayRevolverScheduler.scala:279)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRevolverScheduler.scala:283)
        at akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolverScheduler.scala:235)
        at java.lang.Thread.run(Thread.java:748)

Can somebody  throw some light on this ? Is it problem related to ports / firewall or some setting is messed up ?