Re: [R] Strange behaviour of R?

2020-01-16 Thread Rainer M Krug
Hi

> On 17 Jan 2020, at 08:33, Sigbert Klinke  > wrote:
> 
> Hi,
> 
> I wrote a function like
> 
> test <- function(FUN, args) {
>  print(FUN)
>  FUN(args)
> }
> 
> When I call it lieke this
> 
> test(mean, 1:10)
> test(NULL, 1:10)
> 
> then the second call still uses mean, although I set FUN to NULL. Is that ok?

Not for me - macOS, R 3.6.2


> 
> Actually, I used something like
> 
> test(mean, list(x=1:10, na.rm=TRUE))

Fails as expected,

Rainer

> 
> which actually crashed R, but I can not reproduce it. Of course, when I 
> replaced FUN(args) with do.call(FUN, args) then everything works fine.
> 
> Sigbert
> 
> -- 
> https://hu.berlin/sk 
> https://hu.berlin/mmstat3
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, 
UCT), Dipl. Phys. (Germany)

Orcid ID: -0002-7490-0066

Department of Evolutionary Biology and Environmental Studies
University of Zürich
Office Y34-J-74
Winterthurerstrasse 190
8075 Zürich
Switzerland

Office: +41 (0)44 635 47 64
Cell:   +41 (0)78 630 66 57
email:      rainer.k...@uzh.ch 
rai...@krugs.de 
Skype: RMkrug

PGP: 0x0F52F982





--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, 
UCT), Dipl. Phys. (Germany)

Orcid ID: -0002-7490-0066

Department of Evolutionary Biology and Environmental Studies
University of Zürich
Office Y34-J-74
Winterthurerstrasse 190
8075 Zürich
Switzerland

Office: +41 (0)44 635 47 64
Cell:   +41 (0)78 630 66 57
email:  rainer.k...@uzh.ch
rai...@krugs.de
Skype: RMkrug

PGP: 0x0F52F982




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Strange behaviour of R?

2020-01-16 Thread Sigbert Klinke

Hi,

I wrote a function like

test <- function(FUN, args) {
  print(FUN)
  FUN(args)
}

When I call it lieke this

test(mean, 1:10)
test(NULL, 1:10)

then the second call still uses mean, although I set FUN to NULL. Is 
that ok?


Actually, I used something like

test(mean, list(x=1:10, na.rm=TRUE))

which actually crashed R, but I can not reproduce it. Of course, when I 
replaced FUN(args) with do.call(FUN, args) then everything works fine.


Sigbert

--
https://hu.berlin/sk
https://hu.berlin/mmstat3

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extracting a particular column from list

2020-01-16 Thread Rui Barradas

Hello,

Inline.


Às 22:03 de 16/01/20, Mark Leeds escreveu:

I nominate the last sentence of Rolf's comment as a fortune.


Second.


Rui Barradas




On Thu, Jan 16, 2020 at 3:48 PM Rolf Turner > wrote:



On 17/01/20 1:55 am, Rui Barradas wrote:

 > Hello,
 >
 > What column and what list?
 > Please post a reproducible example, see the link at the bottom of
this
 > mail and  [1], [2], [3].
 >
 > [1] https://cran.r-project.org/web/packages/reprex/index.html
 > [2]
 >

https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

 >
 > [3] https://stackoverflow.com/help/mcve
 >
 > Hope this helps,

The OP should note that lists in general *do not have* columns.  Data
frames (which are a special case of lists) do have columns.

Lists have "*entries*" or "components".  It is important to get your
terminology right and to understand the concepts that you are dealing
with.  Slap-dash hammer and hope is a recipe for disaster, especially
in R.

cheers,

Rolf Turner

-- 
Honorary Research Fellow

Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org  mailing list --
To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extracting a particular column from list

2020-01-16 Thread Rolf Turner



On 17/01/20 1:55 am, Rui Barradas wrote:


Hello,

What column and what list?
Please post a reproducible example, see the link at the bottom of this 
mail and  [1], [2], [3].


[1] https://cran.r-project.org/web/packages/reprex/index.html
[2] 
https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example 


[3] https://stackoverflow.com/help/mcve

Hope this helps,


The OP should note that lists in general *do not have* columns.  Data 
frames (which are a special case of lists) do have columns.


Lists have "*entries*" or "components".  It is important to get your 
terminology right and to understand the concepts that you are dealing 
with.  Slap-dash hammer and hope is a recipe for disaster, especially

in R.

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] citing old(er) versions of packages

2020-01-16 Thread Marc Schwartz via R-help


> On Jan 16, 2020, at 12:03 PM, Ivan Calandra  wrote:
> 
> Dear useRs,
> 
> I want to cite the packages I have used in my analyses for a paper. I
> have recorded through sessionInfo() which packages and which versions I
> used for a given analysis.
> 
> I know how to cite a package using the citation() function, but the
> problem is that in the meantime, I have updated these packages.
> citation() returns the citation for the actual installed version. And
> citations change over time (e.g. with more people getting involved in
> the development and maintenance of a package).
> 
> Now the question is how do I find out how to cite a given, not actual
> version of a package?
> 
> Thank you in advance.
> Best regards,
> Ivan


Hi,

If you know the package versions that you wish to cite and they are no longer 
installed locally, you can use the content of either the CITATION file for the 
package, if included, or the content of the DESCRIPTION file, for the relevant 
version of the package. 

The easiest way to do this may be to download the source tarball for the 
package from the CRAN archive for the package or wherever the package is 
located, if not on CRAN.

An alternative, if the package is stored in an online VC system (e.g. Github), 
is that you may be able to read the relevant file from that system for the 
version of the file that is tagged appropriately.

Regards,

Marc Schwartz

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] citing old(er) versions of packages

2020-01-16 Thread Ivan Calandra
Dear useRs,

I want to cite the packages I have used in my analyses for a paper. I
have recorded through sessionInfo() which packages and which versions I
used for a given analysis.

I know how to cite a package using the citation() function, but the
problem is that in the meantime, I have updated these packages.
citation() returns the citation for the actual installed version. And
citations change over time (e.g. with more people getting involved in
the development and maintenance of a package).

Now the question is how do I find out how to cite a given, not actual
version of a package?

Thank you in advance.
Best regards,
Ivan

-- 
Dr. Ivan Calandra
TraCEr, laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to save multiple values of a variable in a json file in R

2020-01-16 Thread Ioanna Ioannou
ok, my problem is the follwoing
a<- read_json(json_file)
a$fields$geo_applicability$fields$countries[[1]]$fields$name

this was i can see the name of a single country reported first in the json. 
HOwever, i  need to save all 59. My worry is that i have multiple files that i 
need to read and in some cases there will be one country reported and in some 
others multiple. How can i optimise the code?

Best,


From: Rainer M Krug 
Sent: 16 January 2020 14:47
To: Ioanna Ioannou 
Subject: Re: [R] How to save multiple values of a variable in a json file in R

Check the hep of the read_json() function and please keep the conversation on 
the list

On 16 Jan 2020, at 15:42, Ioanna Ioannou 
mailto:ii54...@msn.com>> wrote:

I will try the package but i could do with a worked example.


From: Rainer M Krug mailto:rai...@krugs.de>>
Sent: 16 January 2020 14:29
To: Ioanna Ioannou mailto:ii54...@msn.com>>
Subject: Re: [R] How to save multiple values of a variable in a json file in R

Have you looked at the jsonlite package?

Rainer


On 16 Jan 2020, at 15:21, Ioanna Ioannou 
mailto:ii54...@msn.com>> wrote:

hello everyone,

and happy new year!

I have this problem: I want to save the name of the 'countries', the 
'taxonomy_gem' and the 'minimum_im' and 'maximum_im' . The problem is that 
there are several names of countries.  How can i transfer the information from 
the json file to an R data.frame? See below for the json file.

Best,
ioanna



json_file<- {
   "pk": 670,
   "model": "vulnerability.generalinformation",
   "fields": {
   "category": "Structure class",
   "article_title": "A GLOBAL DATABASE OF VULNERABILITY MODELS FOR SEISMIC 
RISK ASSESSMENT",
   "name": "CR/LFINF/DUL/H:2",
   "publication_conference_name": "16EECE",
   "llrs": null,
   "material": null,
   "web_link": "",
   "owner": {
   "pk": 1900,
   "model": "people.profile",
   "fields": {
   "username": "lmartins",
   "first_name": "",
   "last_name": "",
   "email": 
"luis.mart...@globalquakemodel.org"
   }
   },
   "general_comments": "",
   "geo_applicability": {
   "pk": 669,
   "model": "vulnerability.geoapplicability",
   "fields": {
   "general_information": 670,
   "area": "",
   "countries": [
   {
   "pk": "CIV",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Cte d'Ivoire"
   }
   },
   {
   "pk": "CMR",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Cameroon"
   }
   },
   {
   "pk": "SDN",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Sudan"
   }
   },
   {
   "pk": "SSD",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "South Sudan"
   }
   },
   {
   "pk": "TUN",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Tunisia"
   }
   },
   {
   "pk": "TGO",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "Togo"
   }
   },
   {
   "pk": "ZAF",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
   "region": 2,
   "name": "South Africa"
   }
   },
   {
   "pk": "NER",
   "model": "vulnerability.country",
   "fields": {
   "is_visible": true,
 

[R] How to save multiple values of a variable in a json file in R

2020-01-16 Thread Ioanna Ioannou
hello everyone,

and happy new year!

I have this problem: I want to save the name of the 'countries', the 
'taxonomy_gem' and the 'minimum_im' and 'maximum_im' . The problem is that 
there are several names of countries.  How can i transfer the information from 
the json file to an R data.frame? See below for the json file.

Best,
ioanna



{
"pk": 670,
"model": "vulnerability.generalinformation",
"fields": {
"category": "Structure class",
"article_title": "A GLOBAL DATABASE OF VULNERABILITY MODELS FOR SEISMIC 
RISK ASSESSMENT",
"name": "CR/LFINF/DUL/H:2",
"publication_conference_name": "16EECE",
"llrs": null,
"material": null,
"web_link": "",
"owner": {
"pk": 1900,
"model": "people.profile",
"fields": {
"username": "lmartins",
"first_name": "",
"last_name": "",
"email": "luis.mart...@globalquakemodel.org"
}
},
"general_comments": "",
"geo_applicability": {
"pk": 669,
"model": "vulnerability.geoapplicability",
"fields": {
"general_information": 670,
"area": "",
"countries": [
{
"pk": "CIV",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Cte d'Ivoire"
}
},
{
"pk": "CMR",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Cameroon"
}
},
{
"pk": "SDN",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Sudan"
}
},
{
"pk": "SSD",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "South Sudan"
}
},
{
"pk": "TUN",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Tunisia"
}
},
{
"pk": "TGO",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Togo"
}
},
{
"pk": "ZAF",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "South Africa"
}
},
{
"pk": "NER",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Niger"
}
},
{
"pk": "MAR",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Morocco"
}
},
{
"pk": "KEN",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Kenya"
}
},
{
"pk": "SYC",
"model": "vulnerability.country",
"fields": {
"is_visible": true,
"region": 2,
"name": "Seychelles"
}
  

Re: [R] Extracting a particular column from list

2020-01-16 Thread Rui Barradas

Hello,

What column and what list?
Please post a reproducible example, see the link at the bottom of this 
mail and  [1], [2], [3].


[1] https://cran.r-project.org/web/packages/reprex/index.html
[2] 
https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[3] https://stackoverflow.com/help/mcve

Hope this helps,

Rui Barradas


Às 11:02 de 16/01/20, Faheem Jan via R-help escreveu:

Hi. How to extract a column from the list.. I will be thanks full..

Sent from Yahoo Mail on Android
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reporting missing dates

2020-01-16 Thread David Winsemius
Looks reasonable and efficient. There is a seq.Date function that would be 
implicitly selected by the S3 class dispatch rules  

David

Sent from my iPhone

> On Jan 16, 2020, at 4:28 AM, Jeff Reichman  wrote:
> 
> R-help Forum
> 
> I have a 20 year data set and I am looking for a way to find missing dates.
> I wrote this and its works, but am wounding if there is a better way?
> 
> d <- c('2020-01-01', '2020-01-02', '2020-01-04', '2020-01-05')
> d <- as.Date(d)
> date_range <- seq(min(d), max(d), by = 1) 
> date_range[!date_range %in% d] 
> 
> 
> Sincerely
> 
> Jeff Reichman
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Extracting a particular column from list

2020-01-16 Thread Faheem Jan via R-help
Hi. How to extract a column from the list.. I will be thanks full.. 

Sent from Yahoo Mail on Android
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reporting missing dates

2020-01-16 Thread Enrico Schumann



Quoting Duncan Murdoch :


On 15/01/2020 4:28 p.m., Jeff Reichman wrote:

R-help Forum

I have a 20 year data set and I am looking for a way to find missing dates.
I wrote this and its works, but am wounding if there is a better way?

d <- c('2020-01-01', '2020-01-02', '2020-01-04', '2020-01-05')
d <- as.Date(d)
date_range <- seq(min(d), max(d), by = 1)
date_range[!date_range %in% d]


Another approach would be based on diff(d) - 1.  That will count the  
number of missing dates between any pair of dates that are present:


diff(d) - 1
# Time differences in days
# [1] 0 1 0

That shows that the second date is followed by one missing day.

Duncan Murdoch


But you might want to check if the dates in 'd' are really sorted.

--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reporting missing dates

2020-01-16 Thread Duncan Murdoch

On 15/01/2020 4:28 p.m., Jeff Reichman wrote:

R-help Forum

I have a 20 year data set and I am looking for a way to find missing dates.
I wrote this and its works, but am wounding if there is a better way?

d <- c('2020-01-01', '2020-01-02', '2020-01-04', '2020-01-05')
d <- as.Date(d)
date_range <- seq(min(d), max(d), by = 1)
date_range[!date_range %in% d]


Another approach would be based on diff(d) - 1.  That will count the 
number of missing dates between any pair of dates that are present:


diff(d) - 1
# Time differences in days
# [1] 0 1 0

That shows that the second date is followed by one missing day.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reporting missing dates

2020-01-16 Thread PIKAL Petr
Your approach is quite simple and works well

Another option is
as.Date(setdiff(date_range, d), origin="1970-01-01")
but I do not believe that it has some advantage above yours.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Jeff Reichman
> Sent: Wednesday, January 15, 2020 10:28 PM
> To: R-help@r-project.org
> Subject: [R] Reporting missing dates
> 
> R-help Forum
> 
> I have a 20 year data set and I am looking for a way to find missing
dates.
> I wrote this and its works, but am wounding if there is a better way?
> 
> d <- c('2020-01-01', '2020-01-02', '2020-01-04', '2020-01-05')
> d <- as.Date(d)
> date_range <- seq(min(d), max(d), by = 1)
> date_range[!date_range %in% d]
> 
> 
> Sincerely
> 
> Jeff Reichman
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Course: Zero-inflated GAMs and GAMMs for the analysis of spatial and spatial-temporal correlated data using R-INLA

2020-01-16 Thread Highland Statistics Ltd



We would like to announce the following statistics course.

Course: Zero-inflated GAMs and GAMMs for the analysis of spatial and 
spatial-temporal correlated data using R-INLA


Where and when: NIOZ, Texel, The Netherlands. 20 - 24 April 2020

Course website: http://highstat.com/index.php/courses-upcoming
Course flyer: 
http://highstat.com/Courses/Flyers/2020/Flyer2020_05NIOZ_GAMZISPatTemp.pdf


Kind regards,


Alain Zuur

--

Dr. Alain F. Zuur
Highland Statistics Ltd.
9 St Clair Wynd
AB41 6DZ Newburgh, UK
Email: highs...@highstat.com
URL:   www.highstat.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.