kaitlyngaynor / gorongosa-mesocarnivores

2 stars 0 forks source link

How to pull a data frame from within the function? #117

Closed klg-2016 closed 3 years ago

klg-2016 commented 3 years ago

https://github.com/kaitlyngaynor/gorongosa-mesocarnivores/blob/955c823c975f2810280dc8b99607a169bcced54a/scripts/multi-season%20model/01-multi-season-data-prep.R#L205

I'm trying to make it so that DetHist_complete is accessible outside the function for each species. That's what goes into the umf. When I run this line, something happens to one of the rows/cameras (the output only has 59 rows), and the columns/rows have funky names. Is there a more straightforward way to achieve what I'm trying to do? /Can you see anything immediately wrong with how I'm doing what I'm trying to do?

klg-2016 commented 3 years ago

When I just run a single season's detection history, the row names are the site names, and the column names are "detection_history.o1"... (Not sure those names will matter when making the umf)

klg-2016 commented 3 years ago

I ran it again and got this: Parsed with column specification: cols( .default = col_double() ) See spec(...) for full column specifications. Warning messages: 1: Missing column names filled in: 'X123' [123], 'X124' [124], 'X125' [125], 'X126' [126], 'X127' [127], 'X128' [128], 'X129' [129], 'X130' [130], 'X131' [131], 'X132' [132], 'X133' [133], 'X134' [134], 'X135' [135], 'X136' [136], 'X137' [137], 'X138' [138], 'X139' [139], 'X140' [140], 'X141' [141], 'X142' [142], 'X143' [143], 'X144' [144], 'X145' [145], 'X146' [146], 'X147' [147], 'X148' [148], 'X149' [149], 'X150' [150], 'X151' [151], 'X152' [152], 'X153' [153], 'X154' [154], 'X155' [155], 'X156' [156], 'X157' [157], 'X158' [158], 'X159' [159], 'X160' [160], 'X161' [161], 'X162' [162], 'X163' [163], 'X164' [164], 'X165' [165], 'X166' [166], 'X167' [167], 'X168' [168], 'X169' [169], 'X170' [170], 'X171' [171], 'X172' [172], 'X173' [173], 'X174' [174], 'X175' [175], 'X176' [176], 'X177' [177], 'X178' [178], 'X179' [179], 'X180' [180], 'X181' [181], 'X182' [182], 'X183' [183], 'X184' [184], 'X185' [185], 'X186' [186], 'X187' [187], 'X188' [188], 'X189' [189], 'X190' [190], 'X191' [191], 'X192' [192], 'X193' [193], 'X194' [194], 'X195' [195], 'X196' [196], 'X197' [197], 'X198' [198], 'X199' [199], 'X200' [200], 'X201' [201], 'X202' [202], 'X203' [203], 'X204' [204], 'X205' [205], 'X206' [206], 'X207' [207], 'X208' [208], 'X209' [209], 'X210' [210], 'X211' [211], 'X212' [212], 'X213' [213], 'X214' [214], 'X215' [215], 'X216' [216], 'X217' [217], 'X218' [218], 'X219' [219], 'X220' [220], 'X221' [221], 'X222' [222], 'X223' [223], 'X224' [224], 'X225' [225], 'X226' [226], 'X227' [227], 'X228' [228], 'X229' [229], 'X230' [230], 'X231' [231], 'X232' [232], 'X233' [233], 'X234' [234], 'X235' [235], 'X236' [236], 'X237' [237], 'X238' [238], 'X239' [239], 'X240' [240], 'X241' [241], 'X242' [242], 'X243' [243], 'X244' [244], 'X245' [245], 'X246' [246], 'X247' [247], 'X248' [248], 'X249' [249], 'X250' [250], 'X251' [251], 'X252' [252], 'X253' [253], 'X254' [254], 'X255' [255], 'X256' [256], 'X257' [257], 'X258' [258], 'X259' [259], 'X260' [260], 'X261' [261], 'X262' [262], 'X263' [263], 'X264' [264], 'X265' [265], 'X266' [266], 'X267' [267], 'X268' [268], 'X269' [269], 'X270' [270], 'X271' [271], 'X272' [272], 'X273' [273], 'X274' [274], 'X275' [275], 'X276' [276], 'X277' [277], 'X278' [278], 'X279' [279], 'X280' [280], 'X281' [281], 'X282' [282], 'X283' [283], 'X284' [284], 'X285' [285], 'X286' [286], 'X287' [287], 'X288' [288], 'X289' [289], 'X290' [290], 'X291' [291], 'X292' [292], 'X293' [293], 'X294' [294], 'X295' [295], 'X296' [296], 'X297' [297], 'X298' [298], 'X299' [299], 'X300' [300], 'X301' [301], 'X302' [302], 'X303' [303], 'X304' [304], 'X305' [305], 'X306' [306], 'X307' [307], 'X308' [308], 'X309' [309], 'X310' [310], 'X311' [311], 'X312' [312], 'X313' [313], 'X314' [314], 'X315' [315], 'X316' [316], 'X317' [317], 'X318' [318], 'X319' [319], 'X320' [320], 'X321' [321], 'X322' [322], 'X323' [323], 'X324' [324], 'X325' [325], 'X326' [326], 'X327' [327], 'X328' [328], 'X329' [329], 'X330' [330], 'X331' [331], 'X332' [332], 'X333' [333], 'X334' [334], 'X335' [335], 'X336' [336], 'X337' [337], 'X338' [338], 'X339' [339], 'X340' [340], 'X341' [341], 'X342' [342], 'X343' [343], 'X344' [344], 'X345' [345], 'X346' [346], 'X347' [347], 'X348' [348], 'X349' [349], 'X350' [350], 'X351' [351], 'X352' [352], 'X353' [353], 'X354' [354], 'X355' [355], 'X356' [356], 'X357' [357], 'X358' [358], 'X359' [359], 'X360' [360], 'X361' [361], 'X362' [362], 'X363' [363], 'X364' [364], 'X365' [365], 'X366' [366], 'X367' [367], 'X368' [368], 'X369' [369], 'X370' [370], 'X371' [371], 'X372' [372], 'X373' [373], 'X374' [374], 'X375' [375], 'X376' [376], 'X377' [377], 'X378' [378], 'X379' [379], 'X380' [380], 'X381' [381], 'X382' [382], 'X383' [383], 'X384' [384], 'X385' [385], 'X386' [386], 'X387' [387], 'X388' [388], 'X389' [389], 'X390' [390], 'X391' [391], 'X392' [392], 'X393' [393], 'X394' [394], 'X395' [395], 'X396' [396], 'X397' [397], 'X398' [398], 'X399' [399], 'X400' [400], 'X401' [401], 'X402' [402], 'X403' [403], 'X404' [404], 'X405' [405], 'X406' [406], 'X407' [407], 'X408' [408], 'X409' [409], 'X410' [410], 'X411' [411], 'X412' [412], 'X413' [413], 'X414' [414], 'X415' [415], 'X416' [416], 'X417' [417], 'X418' [418], 'X419' [419], 'X420' [420], 'X421' [421], 'X422' [422], 'X423' [423], 'X424' [424], 'X425' [425], 'X426' [426], 'X427' [427], 'X428' [428], 'X429' [429], 'X430' [430], 'X431' [431], 'X432' [432], 'X433' [433], 'X434' [434], 'X435' [435], 'X436' [436], 'X437' [437], 'X438' [438], 'X439' [439], 'X440' [440] 2: Duplicated column names deduplicated: '0' => '0_1' [3], '0' => '0_2' [4], '0' => '0_3' [5], '0' => '0_4' [6], '0' => '0_5' [7], '0' => '0_6' [8], '0' => '0_7' [9], '0' => '0_8' [10], '0' => '0_9' [11], '0' => '0_10' [12], '0' => '0_11' [13], '0' => '0_12' [14], '0' => '0_13' [15], '0' => '0_14' [16], '0' => '0_15' [17], '0' => '0_16' [18], '0' => '0_17' [19], '0' => '0_18' [20], '0' => '0_19' [21], '0' => '0_20' [22], '0' => '0_21' [23], '0' => '0_22' [24], '0' => '0_23' [25], '0' => '0_24' [26], '0' => '0_25' [27], '0' => '0_26' [28], '1' => '1_1' [29], '0' => '0_27' [30], '0' => '0_28' [31], '0' => '0_29' [32], '0' => '0_30' [33], '0' => '0_31' [34], '0' => '0_32' [35], '0' => '0_33' [36], '0' => '0_34' [37], '0' => '0_35' [38], '0' => '0_36' [39], '0' => '0_37' [40], '0' => '0_38' [41], '0' => '0_39' [42], '0' => '0_40' [43], '0' => '0_41' [44], '0' => '0_42' [45], '0' => '0_43' [46], '0' => '0_44' [47], '0' => '0_45' [48], '0' => '0_46' [49], '0' => '0_47' [50], '0' => '0_48' [51], '0' => '0_49' [52], '0' => '0_50' [53], '0' => '0_51' [54], '0' => '0_52' [55], '1' => '1_2' [56], '1' => '1_3' [57], '0' => '0_53' [58], '0' => '0_54' [59], '1' => '1_4' [60], '1' => '1_5' [61], '1' => '1_6' [62], '0' => '0_55' [63], '0' => '0_56' [64], '0' => '0_57' [65], '0' => '0_58' [66], '0' => '0_59' [67], '0' => '0_60' [68], '0' => '0_61' [69], '0' => '0_62' [70], '0' => '0_63' [71], '0' => '0_64' [72], '0' => '0_65' [73], '0' => '0_66' [74], '0' => '0_67' [75], '0' => '0_68' [76], '0' => '0_69' [77], '0' => '0_70' [78], '0' => '0_71' [79], '0' => '0_72' [80], '0' => '0_73' [81], '1' => '1_7' [82], '0' => '0_74' [83], '0' => '0_75' [84], '0' => '0_76' [85], '0' => '0_77' [86], '1' => '1_8' [87], '0' => '0_78' [88], '0' => '0_79' [89], '1' => '1_9' [90], '0' => '0_80' [91], '0' => '0_81' [92], '0' => '0_82' [93], '1' => '1_10' [94], '0' => '0_83' [95], '1' => '1_11' [96], '0' => '0_84' [97], '0' => '0_85' [98], '0' => '0_86' [99], '0' => '0_87' [100], '0' => '0_88' [101], '1' => '1_12' [102], '1' => '1_13' [103], '0' => '0_89' [104], '0' => '0_90' [105], '0' => '0_91' [106], '0' => '0_92' [107], '0' => '0_93' [108], '0' => '0_94' [109], '0' => '0_95' [110], '0' => '0_96' [111], '0' => '0_97' [112], '1' => '1_14' [113], '0' => '0_98' [114], '0' => '0_99' [115], '0' => '0_100' [116], '0' => '0_101' [117], '0' => '0_102' [118], '0' => '0_103' [119], '0' => '0_104' [120], '0' => '0_105' [121], '0' => '0_106' [122]

klg-2016 commented 3 years ago

(Sorry for the dump, I'm just trying to keep track of what I'm figuring out)

klg-2016 commented 3 years ago

This is what the output looks like: image

klg-2016 commented 3 years ago

This line might be working! DetHist_genet_complete <- read.csv("data/gorongosa-cameras/derived/genet_complete.csv", header = FALSE)

Will report back

klg-2016 commented 3 years ago

Spot checking, it looks fine--I seem to remember something about using read_csv instead of read.csv; is that something I should worry about?

kaitlyngaynor commented 3 years ago

read_csv and read.csv do different things with formatting (including of column names that start with numbers) so yes, it does matter which you use in some cases (but not all). have a look and see which you need for your purposes!

klg-2016 commented 3 years ago

gotcha--in this case, it seems like read.csv is doing what I want it to do/what I think it should be doing, so I'll stick with it for now