Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all 207101 articles
Browse latest View live

Package ggvoronoi in latest R (4.2.1) in Ubuntu 20.04 LTS failing to install

$
0
0

I have been successfully using the package ggvoronoi even a few weeks ago in R (3+). Until then all of a sudden R started to tell me:

> library(ggvoronoi)Error in library(ggvoronoi) : there is no package called ‘ggvoronoi’

Okay, then I tried to install the package, but then getting the following error:

> install.packages("ggvoronoi")Installing package into ‘/home/pratikmullick/R/x86_64-pc-linux-gnu-library/3.6’(as ‘lib’ is unspecified)Warning in install.packages :  package ‘ggvoronoi’ is not available (for R version 3.6.3)

Finally I updated the R to 4.2.1. This is my sessionInfo()

> sessionInfo()R version 4.2.1 (2022-06-23)Platform: x86_64-pc-linux-gnu (64-bit)Running under: Ubuntu 20.04.4 LTSMatrix products: defaultBLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3locale: [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_IN.UTF-8        [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_IN.UTF-8    LC_MESSAGES=en_US.UTF-8    [7] LC_PAPER=en_IN.UTF-8       LC_NAME=C                  LC_ADDRESS=C              [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_IN.UTF-8 LC_IDENTIFICATION=C       attached base packages:[1] stats     graphics  grDevices utils     datasets  methods   base     loaded via a namespace (and not attached):[1] compiler_4.2.1 tools_4.2.1

But even then the problem with installing ggvoronoi did not solve:

> install.packages('ggvoronoi')Installing package into ‘/home/pratikmullick/R/x86_64-pc-linux-gnu-library/4.2’(as ‘lib’ is unspecified)Warning in install.packages :  package ‘ggvoronoi’ is not available for this version of RA version of this package for your version of R might be available elsewhere,see the ideas athttps://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

Can anyone please help me?


Add a secundary reverse x-axis ggplot2

$
0
0

I have the following data example of a spectral analysis.

    structure(list(x = c(0.555555555555556, 0.555555555555556, 0.555555555555556, 0.555555555555556, 0.555555555555556, 0.555555555555556, 0.555555555555556, 1.11111111111111, 1.11111111111111, 1.11111111111111, 1.11111111111111, 1.11111111111111, 1.11111111111111, 1.11111111111111, 1.66666666666667, 1.66666666666667, 1.66666666666667, 1.66666666666667, 1.66666666666667, 1.66666666666667, 1.66666666666667, 2.22222222222222, 2.22222222222222, 2.22222222222222, 2.22222222222222, 2.22222222222222, 2.22222222222222, 2.22222222222222, 2.77777777777778, 2.77777777777778, 2.77777777777778, 2.77777777777778, 2.77777777777778, 2.77777777777778, 2.77777777777778, 3.33333333333333, 3.33333333333333, 3.33333333333333, 3.33333333333333, 3.33333333333333, 3.33333333333333, 3.33333333333333, 3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889, 3.88888888888889, 4.44444444444444, 4.44444444444444, 4.44444444444444, 4.44444444444444, 4.44444444444444, 4.44444444444444, 4.44444444444444, 5, 5, 5, 5, 5, 5, 5, 5.55555555555556, 5.55555555555556, 5.55555555555556, 5.55555555555556, 5.55555555555556, 5.55555555555556, 5.55555555555556, 6.11111111111111, 6.11111111111111, 6.11111111111111, 6.11111111111111, 6.11111111111111, 6.11111111111111, 6.11111111111111, 6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667, 6.66666666666667, 7.22222222222222, 7.22222222222222, 7.22222222222222, 7.22222222222222, 7.22222222222222, 7.22222222222222, 7.22222222222222, 7.77777777777778, 7.77777777777778, 7.77777777777778, 7.77777777777778, 7.77777777777778, 7.77777777777778, 7.77777777777778, 8.33333333333333, 8.33333333333333, 20, 20, 20, 20.5555555555556, 20.5555555555556, 20.5555555555556, 20.5555555555556, 20.5555555555556, 20.5555555555556, 20.5555555555556, 21.1111111111111, 21.1111111111111, 21.1111111111111, 21.1111111111111, 21.1111111111111, 21.1111111111111, 21.1111111111111, 21.6666666666667, 21.6666666666667, 21.6666666666667, 21.6666666666667, 21.6666666666667, 21.6666666666667, 21.6666666666667, 22.2222222222222, 22.2222222222222, 22.2222222222222, 22.2222222222222, 22.2222222222222, 22.2222222222222, 22.2222222222222, 22.7777777777778, 22.7777777777778, 22.7777777777778, 22.7777777777778, 22.7777777777778, 22.7777777777778, 22.7777777777778, 23.3333333333333, 23.3333333333333, 23.3333333333333, 23.3333333333333, 23.3333333333333, 23.3333333333333, 23.3333333333333, 23.8888888888889, 23.8888888888889, 23.8888888888889, 23.8888888888889, 23.8888888888889, 23.8888888888889, 23.8888888888889, 24.4444444444444, 24.4444444444444, 24.4444444444444, 24.4444444444444, 24.4444444444444, 24.4444444444444, 24.4444444444444, 25, 25, 25, 25, 25, 25, 25, 25.5555555555556, 25.5555555555556, 25.5555555555556, 25.5555555555556, 25.5555555555556, 25.5555555555556, 25.5555555555556, 26.1111111111111, 26.1111111111111, 26.1111111111111, 26.1111111111111, 26.1111111111111, 26.1111111111111, 26.1111111111111, 26.6666666666667, 26.6666666666667, 26.6666666666667, 26.6666666666667, 26.6666666666667, 26.6666666666667, 26.6666666666667, 27.2222222222222, 27.2222222222222, 27.2222222222222, 27.2222222222222, 27.2222222222222, 27.2222222222222, 27.2222222222222, 27.7777777777778, 27.7777777777778, 27.7777777777778, 27.7777777777778, 27.7777777777778, 27.7777777777778, 27.7777777777778), period = c(500, 500, 500, 500, 500, 500, 500, 250, 250, 250, 250, 250, 250, 250, 166.666666666667, 166.666666666667, 166.666666666667, 166.666666666667, 166.666666666667, 166.666666666667, 166.666666666667, 125, 125, 125, 125, 125, 125, 125, 100, 100, 100, 100, 100, 100, 100, 83.3333333333333, 83.3333333333333, 83.3333333333333, 83.3333333333333, 83.3333333333333, 83.3333333333333, 83.3333333333333, 71.4285714285714, 71.4285714285714, 71.4285714285714, 71.4285714285714, 71.4285714285714, 71.4285714285714, 71.4285714285714, 62.5, 62.5, 62.5, 62.5, 62.5, 62.5, 62.5, 55.5555555555555, 55.5555555555555, 55.5555555555555, 55.5555555555555, 55.5555555555555, 55.5555555555555, 55.5555555555555, 50, 50, 50, 50, 50, 50, 50, 45.4545454545455, 45.4545454545455, 45.4545454545455, 45.4545454545455, 45.4545454545455, 45.4545454545455, 45.4545454545455, 41.6666666666667, 41.6666666666667, 41.6666666666667, 41.6666666666667, 41.6666666666667, 41.6666666666667, 41.6666666666667, 38.4615384615385, 38.4615384615385, 38.4615384615385, 38.4615384615385, 38.4615384615385, 38.4615384615385, 38.4615384615385, 35.7142857142857, 35.7142857142857, 35.7142857142857, 35.7142857142857, 35.7142857142857, 35.7142857142857, 35.7142857142857, 33.3333333333333, 33.3333333333333, 13.8888888888889, 13.8888888888889, 13.8888888888889, 13.5135135135135, 13.5135135135135, 13.5135135135135, 13.5135135135135, 13.5135135135135, 13.5135135135135, 13.5135135135135, 13.1578947368421, 13.1578947368421, 13.1578947368421, 13.1578947368421, 13.1578947368421, 13.1578947368421, 13.1578947368421, 12.8205128205128, 12.8205128205128, 12.8205128205128, 12.8205128205128, 12.8205128205128, 12.8205128205128, 12.8205128205128, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.1951219512195, 12.1951219512195, 12.1951219512195, 12.1951219512195, 12.1951219512195, 12.1951219512195, 12.1951219512195, 11.9047619047619, 11.9047619047619, 11.9047619047619, 11.9047619047619, 11.9047619047619, 11.9047619047619, 11.9047619047619, 11.6279069767442, 11.6279069767442, 11.6279069767442, 11.6279069767442, 11.6279069767442, 11.6279069767442, 11.6279069767442, 11.3636363636364, 11.3636363636364, 11.3636363636364, 11.3636363636364, 11.3636363636364, 11.3636363636364, 11.3636363636364, 11.1111111111111, 11.1111111111111, 11.1111111111111, 11.1111111111111, 11.1111111111111, 11.1111111111111, 11.1111111111111, 10.8695652173913, 10.8695652173913, 10.8695652173913, 10.8695652173913, 10.8695652173913, 10.8695652173913, 10.8695652173913, 10.6382978723404, 10.6382978723404, 10.6382978723404, 10.6382978723404, 10.6382978723404, 10.6382978723404, 10.6382978723404, 10.4166666666667, 10.4166666666667, 10.4166666666667, 10.4166666666667, 10.4166666666667, 10.4166666666667, 10.4166666666667, 10.2040816326531, 10.2040816326531, 10.2040816326531, 10.2040816326531, 10.2040816326531, 10.2040816326531, 10.2040816326531, 10, 10, 10, 10, 10, 10, 10), species = c("Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus", "Rhizosolenia robusta", "Chaetoceros", "Complexo Guinardia dactiolosolen", "Complexo Rhizosolenia proboscia", "Coscinodiscus", "Guinardia striata", "Hemidiscus"), spectrum = c(19458.7601688054, 6017.54670807875, 13875.798895155, 159677.693338565, 207621691.203773, 3811.69914489559, 136847.001892711, 14136.4255054037, 8441.65460457696, 17393.0496685474, 107116.8751723, 158729101.553218, 2899.61406378871, 109367.088430288, 9305.87807895499, 11281.5424641351, 18948.4670111303, 60778.6363304813, 110444279.289477, 2115.32504891347, 82832.8053335067, 6763.38451479777, 13121.2658179849, 18038.6267765227, 33607.4069291795, 75631502.7582584, 1728.22087051592, 59272.5054559436, 6245.44059256122, 13042.9317151286, 16194.4712529523, 18396.0869589645, 50308298.062295, 1682.59037360351, 36077.8485929601, 6664.13511764911, 11586.486922396, 14461.3639703533, 8618.02341292554, 30104857.8183676, 1829.55470236216, 17444.1303666995, 6943.30907874546, 10065.8055812394, 12890.3342129596, 3320.87177567782, 15728226.1750519, 1997.19168305309, 7496.86737007204, 6494.49699262939, 8991.0442206116, 11273.6894319914, 1409.95460606118, 7474051.51038637, 2055.47181627523, 3904.59296499914, 5411.21374815554, 8009.43677697422, 9683.94295013324, 905.039269264689, 3534969.07308381, 1969.74548519321, 2645.51718725985, 4213.53795956001, 6835.45158354146, 8278.78258243896, 809.368222992939, 2019242.74949445, 1773.49233642477, 2059.75611657007, 3447.71406634804, 5514.59631583194, 7086.85296659687, 1029.00452520719, 1748319.38289315, 1534.69975564511, 1742.58835496923, 3298.89669166208, 4231.48378350386, 6140.87287688144, 1589.99915823864, 2302513.10644475, 1326.22111477987, 1460.83520829073, 3453.91772758991, 3158.61443762274, 5403.37676725542, 2240.58170330882, 3758051.98565151, 1189.17261885366, 1309.15805660222, 3504.63655589661, 2329.69936849746, 4638.76554233306, 2587.82683410599, 6051426.94566691, 1125.88097909571, 1506.42753971472, 3366.15728607311, 1692.67745433697, 6329281.44510128, 465.097127046975, 2332.26971428103, 1148.91429609005, 1010.16428069083, 1144.84760062549, 835.868490459267, 11786388.5541659, 580.540902458, 4227.58085316718, 2069.70395083785, 1169.22909717042, 1528.89701387316, 1177.81644915265, 17939351.822906, 768.324134796673, 8384.20576538291, 3363.84036374411, 1328.77444763696, 1929.79301008027, 1603.80944005807, 22072551.8733814, 939.826334041237, 13509.5531888272, 4302.05768271601, 1333.90350144186, 2156.0968317067, 1782.90206768143, 22872261.5594672, 1014.72869785231, 16247.7050605495, 4312.08542109906, 1201.00422830325, 2016.3545817191, 1475.80311455503, 20605683.0392986, 987.729636677563, 14326.6597963028, 3502.82884380579, 1068.22635801264, 1584.23902130377, 885.52098211917, 16154018.9493131, 884.051415624282, 9403.97952840475, 2432.21957973094, 1028.44586255351, 1112.2741035284, 425.350674116441, 10888238.7624687, 737.604849745358, 5015.21428958028, 1617.83384179819, 1092.19500833427, 775.417959531656, 262.796338903405, 6523946.78994595, 619.444152461479, 2774.06615995364, 1229.32301921223, 1179.37390691533, 611.832123456465, 270.500063450411, 3935359.27292958, 577.576157910486, 1970.68839372538, 1097.61778471231, 1169.79680158148, 585.861605900478, 306.461937341907, 2636434.34133975, 570.791954699915, 1546.33435152781, 1017.04207010564, 1038.0403368466, 615.924290592657, 384.364356095856, 1844089.45693978, 543.408580746617, 1160.181496196, 948.708595803658, 857.592200250135, 610.549574570753, 573.52359517127, 1330983.85449444, 501.889526739985, 892.119746535025, 920.320333398857, 693.36507826827, 542.752570779926, 823.329956595525, 1143325.45509701, 465.154910154485, 791.361592662822, 912.835866807245, 575.95823079491, 454.877305733286, 992.242337199621, 1157490.54714983, 423.839059200258, 826.196612794713)), row.names = c(NA, -201L), class = c("tbl_df", "tbl", "data.frame"))

And I have the following code to plot:

ggplot(df_spectral) +  geom_line(aes(x = x, y = spectrum, col = species), size = 1) +  geom_point(aes(x = x, y = spectrum), col = "black", size = .03) +  facet_wrap(~species, scales = "free_y") +  scale_x_continuous("x", n.breaks = 10) +  labs(x = "µHz") +  theme_test()

However, I trying to add a secondary x-axis (column period) in a reverse way, below the main x-axis (column x), that is a frequency in µHz.

I don't to do this.

How could I perform this?

I can not run R in Ubuntu 24.04 LTS

$
0
0

I would like an help from an error that I am experiencing after installing R. I followed all steps from "https://cran.r-project.org/bin/linux/ubuntu/fullREADME.html#installing-r" to install R in Ubuntu 24.04 LTS. However, the following error is reported after starting R in my terminal: "/usr/local/lib/R/bin/exec/R: error while loading shared libraries: libicuuc.so.72: cannot open shared object file: No such file or directory". Is there anyway to fix it?

Add Random Effects to Stargazer table

$
0
0

I have a Mixed-effects model and I want to use stargazer to create a regression table including the Random Effects part.

I can get something similar using either sjPlot::tab_model() or texreg::texreg(), but I really wanted to know if there's a way to make it using stargazer.

Thanks in advance!

Example:

library(stargazer)library(sjPlot)library(texreg)mtcars$cyl <- as.factor(mtcars$cyl)# Fit the mixed-effects modelmodel <- lmer(mpg ~ hp + (1 | cyl), data = mtcars)summary(model)# Stargazer does not display the random effects:stargazer(model,           type = "text",          star.cutoffs = c(0.1, 0.05, 0.01, 0.001),          star.char = c("+", "*", "**", "***"),          notes = c("Odds w/ 95% CIs in (parentheses) + p<0.1; * p<0.05; ** p<0.01; *** p<0.001"),          notes.append=F, align = T, ci = T)# (sjPlot) tab_model() does:tab_model(model)# And so does (texreg) texreg():texreg(model, ci.force = T)

R - cannot use autoplot with dataframes

$
0
0

I ran into this when trying to throw together some quick plots for exploratory analysis. I wanted to use the autoplot function from ggplot2 so that I wouldn't have to take the time to specify all the parameters and such. Again, this is for exploratory analysis, not for generating plots to be shared/published.

For a quick, minimal example:

DF <- data.frame(major = c("Bio", "Chem", "Comp", "DataSci", "Maths", "STEM_other"),                 count = c(38, 16, 19, 8, 15, 56))

... which, of course, results in the following dataframe:

> DF       major count1        Bio    382       Chem    163       Comp    194    DataSci     85      Maths    156 STEM_other    56

My hope was that autoplot would give me a simple bar chart or something, just enough for a quick look without too much trouble. When trying to use the autoplot function, I get this error:

> autoplot(DF)Error in `autoplot()`:! Objects of class <data.frame> are not supported by autoplot.ℹ have you loaded the required package?Run `rlang::last_trace()` to see where the error occurred.

It seems odd to me that dataframes would not be supported, when I would think many data sources would be organized in dataframes. Is there something I am missing?

All of my searching pointed to issues with autoplot handling time-series data, which apparently can be corrected by also loading ggfortify. This is not time-series data, so I would think loading ggfortify would not be any help in this case... I tried anyway to confirm, and I was correct (no change).

Is there some other package I need to install/load to make autoplot work? Isn't the point to be able to make quick plots without spending too much time on them, or am I totally misusing autoplot?

Thanks for any guidance.

Reactivity of data.table and dateRangeInput()

$
0
0

I have a functional shinyApp where one data.table summarizes data from two other data.tables based on dates given in dateRangeInput(). Default format for dateRangeInput() is "yyyy-mm-dd". I have changed date formats in dateRangeInput() and date columns of relevant data.tables to "dd/mm/yyyy". Date formats changed successfully, but the summary data.table has lost reactivity to changes of other data.tables. The summary data.table also is not reacting to changes of dates in dateRangeInput().

I have tried it in several ways but unsuccessful. I went thru many questions in this forum but could not find the one which tackled such kind of situation. I would appreciate if someone can show me how to do it or refer to similar questions solved in this forum.

library(shiny)library(shinydashboard)library(rhandsontable)library(data.table)library(dplyr)df1 <- data.table("tableNames" = as.character(c("Pool 1", "Pool 2","Total")),"score1" = as.numeric(c(0,0,0)),"score2" = as.numeric(c(0,0,0)),            stringsAsFactors = FALSE)df2 <- data.table("date" = as.character(c("01/06/2024", "01/06/2024", "03/06/2024", "03/06/2024")),"names" = as.character(c("Bob", "Ali","Bob", "Ali")),"score1" = as.numeric(c(10, 20, 20, 10)),"score2" = as.numeric(c(15, 25, 25, 15)),            stringsAsFactors = FALSE)df3 <- data.table("date" = as.character(c("02/06/2024", "02/06/2024", "04/06/2024", "04/06/2024")),"names" = as.character(c("Bob", "Ali","Bob", "Ali")),"score1" = as.numeric(c(30, 40, 40, 30)),"score2" = as.numeric(c(15, 25, 25, 15)),            stringsAsFactors = FALSE)ui <- fluidPage(   dashboardPage(    dashboardHeader(),    dashboardSidebar(      sidebarMenu(        menuItem("Scores", tabName = "scores",              menuSubItem("ScoreSummary", tabName = "table_df1"),              menuSubItem("Scores_df2", tabName = "table_df2"),              menuSubItem("Scores_df3", tabName = "table_df3")        )      )    ),    dashboardBody(      tabItems(        tabItem(tabName = "table_df1",            column(                width=8,                dateRangeInput("dates", "Choose a period:", format= "dd/mm/yyyy",                     start = "2024-01-01", end = Sys.Date()),                uiOutput("nested_ui")),            column(                width=8,"Summary of scores",                rHandsontableOutput("table1"))        ),        tabItem(tabName = "table_df2",            column(                width=8,"Pool 1",                rHandsontableOutput("table2")          )        ),        tabItem(tabName = "table_df3",            column(                width=8,"Pool 2",                rHandsontableOutput("table3")          )        )      )    )  ))server = function(input, output) {  data <- reactiveValues()  observe({    data$dt1 <- as.data.table(df1)    data$dt2 <- as.data.table(df2)    data$dt3 <- as.data.table(df3)  })  observe({    if(!is.null(input$table1))      data$dt1<- hot_to_r(input$table1)  })  observe({    if(!is.null(input$table2))      data$dt2<- hot_to_r(input$table2)  })  observe({    if(!is.null(input$table3))      data$dt3<- hot_to_r(input$table3)  })  observe({    if (!any(is.na(input$dates))) {      dt2_1 <- data$dt2      selected_dates1 <- seq(as.Date(input$dates[1L]),                             as.Date(input$dates[2L]), by = "day")      data$dt2_2 <- dt2_1[as.Date(dt2_1$date) %in% selected_dates1, ]    } else {      selected_dates2 <- unique(data$dt2$date)      data$dt2_2 <- data$dt2[data$dt2$date %in% selected_dates2, ]    }  })  observe({    if(!is.null(input$table2))      data$dt2_2<- hot_to_r(input$table2)  })  observe({    if (!any(is.na(input$dates))) {      dt3_1 <- data$dt3      selected_dates1 <- seq(as.Date(input$dates[1L]),                             as.Date(input$dates[2L]), by = "day")      data$dt3_2 <- dt3_1[as.Date(dt3_1$date) %in% selected_dates1, ]    } else {      selected_dates2 <- unique(data$dt3$date)      data$dt3_2 <- data$dt3[data$dt3$date %in% selected_dates2, ]    }  })  observe({    if(!is.null(input$table3))      data$dt3_2<- hot_to_r(input$table3)  })  observe({    data$dt1[1, 2:3] <- data$dt2_2[, list(      score1 = sum(score1, na.rm = TRUE),      score2 = sum(score2, na.rm = TRUE)    ), by=`names`][, .(      score1 = sum(score1, na.rm = TRUE),      score2 = sum(score2, na.rm = TRUE))]  })  observe({    data$dt1[2, 2:3] <- data$dt3_2[, list(      score1 = sum(score1, na.rm = TRUE),      score2 = sum(score2, na.rm = TRUE)    ), by=`names`][, .(      score1 = sum(score1, na.rm = TRUE),      score2 = sum(score2, na.rm = TRUE))]  })  observe({ data$dt1[3, 2:3] <- data$dt1[, .SD[1:2, lapply(.SD, sum)], .SDcols = 2:3] })  output$nested_ui <- renderUI(!any(is.na(input$dates)))  output$table1 <- renderRHandsontable({    rhandsontable(data$dt1, stretchH = "all")  })  output$table2 <- renderRHandsontable({    rhandsontable(data$dt2, stretchH = "all") |>    hot_col(1, format="dd/mm/yyyy", type="date")  })  output$table3 <- renderRHandsontable({    rhandsontable(data$dt3, stretchH = "all")|>    hot_col(1, format="dd/mm/yyyy", type="date")  })}shinyApp(ui = ui, server = server)

How to mutate a year quarter str into date?

$
0
0

I have a df that comes from an api with a Trimestre (Código) column in string format:

pib$`Trimestre (Código)` <- c(199101,199102,199103,199104,199201,199202,...)

but i need to mutate this column into date format. I have tried the folowing:

> > pib %>% > mutate(date = parse_date(`Trimestre (Código)`, format='%Y%q')) %>%> select('Trimestre (Código)', "Setores e subsetores", Valor) %>%> pivot_wider(names_from = "Setores e subsetores",> values_from = Valor)

but I just receive the error 'unsupported format %q'. How to do it?

What's MATLAB doing when lu() is called on a rectangular matrix and how do I do the same in R? [duplicate]

$
0
0

So apparently MATLAB is able to perform LU decomposition on a rectangular matrix. In my understanding, [L, U, P, Q] = lu(A) when A is sparse and rectangular in MATLAB performs a rank-revealing LU decomposition using a UMFPACK routine. UMFPACK is part of SuiteSparse, which I understand is what R's Matrix package is based on.

However, trying to use Matrix::lu() on a sparse matrix in R returns an error that the matrix must be square. Is there any analogue of MATLAB's rank-revealing LU decomposition in R?

The problem I'm trying to solve is to implement a particular econometric estimator [1] in R, and the author's code in MATLAB uses LU decomposition as follows:

[L,U,P,Q]=lu(A);diagr = abs(diag(U));r = sum(diagr >=  10^-5); V=Q*U';Vr=V(:,diagr>.5);

so of course if there's any alternate way to get to this I'm all ears. Verifying the condition stated in the paper using pracma's Moore-Penrose inverse fails because the matrix is too large. See also this question.

EDIT: I tried the following using RcppEigen, as I understand that Eigen's SparseLU works on arbitrary matrices, but apparently the way the matrices are stored doesn't allow for easy conversion to a PermutationMatrix or SparseMatrix.

#include <RcppEigen.h>// [[Rcpp::depends(RcppEigen)]]using namespace Rcpp;// [[Rcpp::export]]List rectangularSparseLU(const Eigen::MappedSparseMatrix<double> & A) {    Eigen::SparseLU<Eigen::SparseMatrix<double>> lu;    lu.analyzePattern(A);    lu.factorize(A);    Eigen::SparseMatrix<double> L = lu.matrixL();    Eigen::SparseMatrix<double> U = lu.matrixU();    Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> P = lu.rowsPermutation();    Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> Q = lu.colsPermutation();    return List::create(Named("L") = L,                        Named("U") = U,                        Named("P") = P,                        Named("Q") = Q);}

[1] https://arxiv.org/abs/2102.01802


Summary statistics in data.table using quantile and other statistics

$
0
0

I am attempting to summarize data using data.table in R. The problem is that within my summarization framework the use of quantile spits out the results in rows instead of columns. I have a simple enough workaround, but I wanted to see if there is a more direct way to get the output I want.

library(data.table)library(magrittr)#create some example datadt<-data.table(ID=rep(1:3, each=100),              val=rnorm(300,100, sd=20))#define percentiles of interestpercs=c(0.05, 0.10, 0.50, 0.75, 0.90, 0.95)

The following code provides all of the data I want, but not in the format I want. It puts each percentile on a new row and then replicates the previous summary statistics (mean, median, max min). I want each percentile in a new column.

#Summarize the data - this is the brevity I want but the format puts the percentiles in new rowsdt[,.(mean=mean(val, na.rm=T),      Median=median(val, na.rm=T),      min=min(val, na.rm=T),      max=max(val, na.rm=T),      as.list(quantile(val, probs=percs, na.rm=T))),   by=ID]

The following code gives me the format I want, but now I am doing two operations and gluing the results together. Ultimately this is fine, but I would rather a code structure like the previous snippet with output formatted as below.

#summarize data - this is the format I want it in but don't want the extra operationsdt[,.(mean=mean(val, na.rm=T),      Median=median(val, na.rm=T),      min=min(val, na.rm=T),      max=max(val, na.rm=T)),    by=ID]%>%cbind(.,dt[,setDT(as.list(quantile(val, probs=percs, na.rm=T))),by=ID][,-1]) #-1 to remove extraneous ID column

ifelse() stripping POSIXct attribute from vector of timestamps?

$
0
0

This is weird: R's ifelse() seems to do some (unwanted) casting:Lets say I have a vector of timestamps (possibly NA) and NA values should be treated differently than existing dates, for example, just ignored:

formatString = "%Y-%m-%d %H:%M:%OS"timestamp = c(as.POSIXct(strptime("2000-01-01 12:00:00.000000", formatString)) + (1:3)*30, NA)

Now

timestamp#[1] "2000-01-01 12:00:30 CET""2000-01-01 12:01:00 CET""2000-01-01 12:01:30 CET"#[6] NA    

as desired but translation by 30 seconds results in

ifelse(is.na(timestamp), NA, timestamp+30)#[1] 946724460 946724490 946724520        NA

Notice that still, timestamp+30 works as expected but lets say I want to replace NA dates by a fixed date and translate all the others by 30 secs:

fixedDate = as.POSIXct(strptime("2000-01-01 12:00:00.000000", formatString))ifelse(is.na(timestamp), fixedDate, timestamp+30)#[1] 946724460 946724490 946724520 946724400

Question: whats wrong with this solution and why doesn't it work as expected?

Edit: the desired output is a vector of timestamps (not of integers) translated by 30 secs and the NA's being replaced by whatever...

R bar chart with three factors

$
0
0

I want to combine the information of three factors and I can't get it fixed.

The model:The minimum working code covers a course with module A and B that is attended by males and females having different education levels.The bar chart with education levels per module is achieved (see below)

Given the produced bar chart, I would like to have another fill on gender in each education bar; is that possible?

module<-as.factor(c(rep("A",5), rep( "B",6)))gender<-as.factor(c(rep("female",2), rep("male",3), rep("female",3), rep("male",3)))# primary, secondary tertiaryedu<-as.factor(c("prim", "sec", "tert", "prim", "sec", "tert","prim", "sec", "tert","prim", "sec"))course<-data.frame(module, gender, edu)library(ggplot2)bar_edu<-ggplot(course, aes(module, fill=edu))bar_edu+geom_bar(position="dodge")

how sort in reverse order xts object

$
0
0

I'm trying to do a regular reverse sort, but I don't understand how to do it with an xts object. I want the last date to be in the first line and not the last.I tried several ways but it doesn't work.

library(xts)x <- rnorm(500) |> cumsum() |> round(1) |>                   xts(Sys.time()+1:500) |> to.minutes(name = NULL) # dont work :(# x[nrow(x):1,]# x[order(index(x),decreasing = T),]# rev(x)

Transform the value of column to number of rows in dataframe [duplicate]

$
0
0

I want to transform the column value to number of rows.

E.g.

data1|Month     | Number || --------| -------- || March   |       1  || April   |       2  || April   |       2  |

The output I want

|Month    | Number || --------| -------- || March   |       1  || April   |       1  || April   |       1  || April   |       1  || April   |       1  |

I tried running this script and got the error message below:

data1 %>%    ungroup %>%    uncount(Number)Error in `uncount()`:! `weights` can't be missing. Location ... is missing.

ggsurvplot not displaying combined survival curve with add.all = TRUE when Faceting

$
0
0

I am trying to create survival plots using the survminer package in R with data split by genetic mutations and include a summary line representing all individuals across facets. The survival analysis and plotting work fine when not using add.all in ggsurvplot for multiple groups (split by sex and mutation type). However, when attempting to add a combined survival curve across facets using add.all = TRUE, it doesn't show as expected. Below is a minimal reproducible example using the lung dataset:

example:

    library(survival) ; library(survminer)set.seed(102030)lung <- lung %>% mutate( mut = sample(c("mutA","mutB"), nrow(lung), replace = T, prob = c(0.5,0.5))) # create 2 groups for demo# Basic survival curvesfit1 <- survfit(Surv(time, status) ~ 1 , data = lung) # general overall survival ggsurvplot(fit1 , data = lung)# Basic survival curves with 2 groups for sexfit2 <- survfit(Surv(time, status) ~ sex , data = lung)ggsurvplot(fit2 , data = lung) # Survival curves with 2 variables and 2 groups per variable (problematic part)fit3 <- survfit(Surv(time, status) ~ sex + mut, data = lung)ggsurvplot(fit3 , data = lung, facet.by = "mut") # example one facet by mut. Works as intended!ggsurvplot(fit3 , data = lung,            facet.by = "mut",            add.all = T) # supposedly should have added a third groups (i.e. a line that represents the number of individuals in each facet) # I also tried this approach, but this is not faceting the plot either.ggsurvplot_combine(  list(fit1, fit3),  list(lung, lung),  facet.by = "mut",  pval = TRUE,  risk.table = TRUE,  conf.int = F,  palette = "jco")

I expect the add.all = TRUE parameter to add a summary curve across the facets, but this does not occur. How can I correct this issue or is there a limitation in the function?It might be that I need to use ggsurvplot_group_by or ggsurvplot_facet differently.

Error in download data from yahoo in r using tq_get function

$
0
0

i want to download the stock data. When i use the tq_get function, it shows that Caused by warning:

! x = 'RCL', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "RCL", env = <environment>, verbose = FALSE, : Unable to import “RCL”.HTTP error 403.

So how can i download the stock data, please help.

enter image description here

I tried many ways but it still can not download the stock


"Furrr" package R: future_pmap incorrect number of dimensions; Caused by attempted extraction of matrix rows; .l is two variables

$
0
0

I suspect the error is related to my lack of understanding of how to run this function multiple times using future_pmap; as you can see below I designate Ntrials to demonstrate that I desire the function to run 20 times in this particular scenario. Be mindful of the cores you are using if you wish to assist through replication of the code.

library("furrr")library("parallel")testmatrix<-matrix(runif((20000*11),-1,21),nrow = 20000, ncol = 11)Testfunction<-function(ParVp,Ntrials){  for(simnum in 1:Ntrials){    #locate parameters for in-host dynamics    Vp=ParVp[, 1:2]    tp=ParVp[, 3:4]    lg=ParVp[, 5:6]    ld=ParVp[, 7:8]    Tc=ParVp[, 9:10]    rho=ParVp[, 11]  print(head(Vp))  }}ncores<-detectCores()-2plan(multisession, workers = ncores)Testoutput<- future_pmap(list(testmatrix,20),Testfunction)plan(sequential)

Error in (function (.l, .f, ..., .progress = FALSE) :ℹ In index: 1.Caused by error in ParVp[, 1:2]:! incorrect number of dimensions

Using an R studio server built on University GPU - Package installation stops and prompts resulting in a non zero exit status

$
0
0

I have been using a GPU hosted RStudio server to conduct a bunch of analyses. Whilst I was able to install a few packages and run them, however, for some other packages despite installation - they result in a non zero exit. I have not been able to figure out what is causing this issue. I tried multiple ways to install them with zero success. It is something new to me and I frankly am not even sure what and where to look for solutions on the internet. Could someone let me know how to conduct a diagnostic and understand what's causing the issue? Thanks in advance

The following error pops up when I try to install something as basic as Tidyverse

Would appreciate some feedback as am totally new to using R on a GPU hosted server

* installing *source* package ‘curl’ ...** package ‘curl’ successfully unpacked and MD5 sums checked** using staged installationPackage libcurl was not found in the pkg-config search path.Perhaps you should add the directory containing `libcurl.pc'to the PKG_CONFIG_PATH environment variableNo package 'libcurl' foundPackage libcurl was not found in the pkg-config search path.Perhaps you should add the directory containing `libcurl.pc'to the PKG_CONFIG_PATH environment variableNo package 'libcurl' foundUsing PKG_CFLAGS=Using PKG_LIBS=-lcurl--------------------------- [ANTICONF] --------------------------------Configuration failed because libcurl was not found. Try installing: * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc) * rpm: libcurl-devel (Fedora, CentOS, RHEL)If libcurl is already installed, check that 'pkg-config' is in yourPATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-configis unavailable you can set INCLUDE_DIR and LIB_DIR manually via:R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'-------------------------- [ERROR MESSAGE] ---------------------------<stdin>:1:10: fatal error: curl/curl.h: No such file or directorycompilation terminated.--------------------------------------------------------------------ERROR: configuration failed for package ‘curl’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/curl’Warning in install.packages :  installation of package ‘curl’ had non-zero exit status* installing *source* package ‘systemfonts’ ...** package ‘systemfonts’ successfully unpacked and MD5 sums checked** using staged installationPackage fontconfig was not found in the pkg-config search path.Perhaps you should add the directory containing `fontconfig.pc'to the PKG_CONFIG_PATH environment variableNo package 'fontconfig' foundPackage freetype2 was not found in the pkg-config search path.Perhaps you should add the directory containing `freetype2.pc'to the PKG_CONFIG_PATH environment variableNo package 'freetype2' foundUsing PKG_CFLAGS=Using PKG_LIBS=-lfontconfig -lfreetype--------------------------- [ANTICONF] --------------------------------Configuration failed to find the fontconfig freetype2 library. Try installing: * deb: libfontconfig1-dev (Debian, Ubuntu, etc) * rpm: fontconfig-devel (Fedora, EPEL) * csw: fontconfig_dev (Solaris) * brew: freetype (OSX)If fontconfig freetype2 is already installed, check that 'pkg-config' is in yourPATH and PKG_CONFIG_PATH contains a fontconfig freetype2.pc file. If pkg-configis unavailable you can set INCLUDE_DIR and LIB_DIR manually via:R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'-------------------------- [ERROR MESSAGE] ---------------------------<stdin>:1:10: fatal error: fontconfig/fontconfig.h: No such file or directorycompilation terminated.--------------------------------------------------------------------ERROR: configuration failed for package ‘systemfonts’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/systemfonts’Warning in install.packages :  installation of package ‘systemfonts’ had non-zero exit statusERROR: failed to lock directory ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1’ for modifyingTry removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-stringi’Warning in install.packages :  installation of package ‘stringi’ had non-zero exit status* installing *source* package ‘xml2’ ...** package ‘xml2’ successfully unpacked and MD5 sums checked** using staged installationPackage libxml-2.0 was not found in the pkg-config search path.Perhaps you should add the directory containing `libxml-2.0.pc'to the PKG_CONFIG_PATH environment variableNo package 'libxml-2.0' foundPackage libxml-2.0 was not found in the pkg-config search path.Perhaps you should add the directory containing `libxml-2.0.pc'to the PKG_CONFIG_PATH environment variableNo package 'libxml-2.0' foundUsing PKG_CFLAGS=Using PKG_LIBS=-lxml2------------------------- ANTICONF ERROR ---------------------------Configuration failed because libxml-2.0 was not found. Try installing: * deb: libxml2-dev (Debian, Ubuntu, etc) * rpm: libxml2-devel (Fedora, CentOS, RHEL) * csw: libxml2_dev (Solaris)If libxml-2.0 is already installed, check that 'pkg-config' is in yourPATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-configis unavailable you can set INCLUDE_DIR and LIB_DIR manually via:R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'--------------------------------------------------------------------ERROR: configuration failed for package ‘xml2’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/xml2’Warning in install.packages :  installation of package ‘xml2’ had non-zero exit statusERROR: dependency ‘systemfonts’ is not available for package ‘textshaping’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/textshaping’Warning in install.packages :  installation of package ‘textshaping’ had non-zero exit statusERROR: dependency ‘curl’ is not available for package ‘httr’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/httr’Warning in install.packages :  installation of package ‘httr’ had non-zero exit statusERROR: dependency ‘stringi’ is not available for package ‘stringr’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/stringr’Warning in install.packages :  installation of package ‘stringr’ had non-zero exit statusERROR: dependency ‘httr’ is not available for package ‘gargle’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/gargle’Warning in install.packages :  installation of package ‘gargle’ had non-zero exit statusERROR: dependency ‘stringr’ is not available for package ‘selectr’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/selectr’Warning in install.packages :  installation of package ‘selectr’ had non-zero exit statusERROR: dependencies ‘systemfonts’, ‘textshaping’ are not available for package ‘ragg’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/ragg’Warning in install.packages :  installation of package ‘ragg’ had non-zero exit statusERROR: dependency ‘stringr’ is not available for package ‘tidyr’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/tidyr’Warning in install.packages :  installation of package ‘tidyr’ had non-zero exit statusERROR: dependencies ‘stringr’, ‘tidyr’ are not available for package ‘broom’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/broom’Warning in install.packages :  installation of package ‘broom’ had non-zero exit statusERROR: dependency ‘tidyr’ is not available for package ‘dbplyr’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/dbplyr’Warning in install.packages :  installation of package ‘dbplyr’ had non-zero exit statusERROR: dependencies ‘gargle’, ‘httr’ are not available for package ‘googledrive’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/googledrive’Warning in install.packages :  installation of package ‘googledrive’ had non-zero exit statusERROR: dependencies ‘httr’, ‘selectr’, ‘xml2’ are not available for package ‘rvest’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/rvest’Warning in install.packages :  installation of package ‘rvest’ had non-zero exit statusERROR: dependencies ‘curl’, ‘gargle’, ‘googledrive’, ‘httr’ are not available for package ‘googlesheets4’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/googlesheets4’Warning in install.packages :  installation of package ‘googlesheets4’ had non-zero exit statusERROR: dependencies ‘broom’, ‘tidyr’ are not available for package ‘modelr’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/modelr’Warning in install.packages :  installation of package ‘modelr’ had non-zero exit statusERROR: dependencies ‘broom’, ‘dbplyr’, ‘googledrive’, ‘googlesheets4’, ‘httr’, ‘modelr’, ‘ragg’, ‘rvest’, ‘stringr’, ‘tidyr’, ‘xml2’ are not available for package ‘tidyverse’* removing ‘/raid/home/soundai/R/x86_64-pc-linux-gnu-library/4.1/tidyverse’Warning in install.packages :  installation of package ‘tidyverse’ had non-zero exit status

Read large number of small files efficiently in R

$
0
0

I have about 700K small files (condor logs files and less than 10 KB). There are no rules for filenames. I am using list.files to obtain all filenames, then reading them with readLines, and merge them as a list.

Currently It will take several hours to read all files. These are my codes to read log files.

rm(list = ls())base <- 'logs-025'exts <- c('log', 'out', 'err')for (i in seq(along = exts)){    all_files <- list.files(base, paste0('apsim_.*.', exts[i]), full.names = TRUE)    res <- NULL    for (j in seq(along = all_files))    {        res_j <- readLines(all_files[j])        res[[j]] <- res_j    }    save(res, file = paste0(Sys.info()['nodename'], '-', exts[i], '.RData'))}

Is there a efficiently way to read large number of small files in R?

Thanks for any advice.

Cheers,Bangyou

How to use Rsqlite to save and load data in sqlite

$
0
0

I am learning SQLite and I have a big data frame in csv format and I imported into the SQLite.

db <- dbConnect(SQLite(), dbname="myDB.sqlite")dbWriteTable(conn = db, name = "myDB", dataframe, overwrite=T,         row.names=FALSE)

after that, I saw there is a myDB.sqlite in my directory but with zero byte. How can I save the dataframe in the sqlite so that I don't need to write table everytime. Thanks.

DBI dbExecute not working with Oracle Database [duplicate]

$
0
0

I have a RJDBC-connection with an Oracle Database and run the following example:

dbWriteTable(con, "cars", head(cars, 3))dbReadTable(con, "cars")   # there are 3 rows

This works fine. However, if I run the following line, I get an error:

dbExecute(con,"INSERT INTO cars (speed, dist) VALUES (1, 1), (2, 2), (3, 3)")

The error I get is:

Error in dbSendQuery(conn, statement, ...) :   Unable to retrieve JDBC result set  JDBC ERROR: ORA-00933: SQL-Befehl was not correctly finished  Statement: INSERT INTO cars (speed, dist) VALUES (1, 1), (2, 2), (3, 3)

Any idea what I am missing here? The example was taken from https://rdrr.io/cran/DBI/man/dbExecute.html.

Viewing all 207101 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>