0

Names have been attached to the five elements of a list of dataframes clusts as follows:

names(clusts) = paste("clust",1:length(clusts),sep="")

The names are as desired:

print(names(clusts))

"clust1" "clust2" "clust3" "clust4" "clust5"

However - as one might guess - those names are limited in scope to the list itself - and in particular are not visible in the global scope :

print(ls())

"clusts"  (and others..)  

This leads to sqldf not being able to "see" those dataframes.. Is there a way to make them visible at the global scope (and thus to sqldf) ?

Update Tried using with per comment of @thelatemail :

with(clusts,
    meanDfs2<-lapply(clustxs, function(clustx) {
        clust = clustx[[1]]; x = clustx[[2]]
        return(ssql(str('select cid, count(1) cnt from clust',x,' group by cid order by 2 desc')))
    })
)

But it does not seem to be working:

Error in rsqlite_send_query(conn@ptr, statement) : no such table: clust1

It was a nice idea though!

6
  • Using ?with maybe? Like with(clusts, <sqldf code here>) Commented Jun 25, 2018 at 3:50
  • nice idea! trying it now.. hmm.. does not seem to be working.. seemed like a good idea.. (see updated OP) Commented Jun 25, 2018 at 3:53
  • does fn$sqldf work for this case? Commented Jun 25, 2018 at 4:29
  • not sure I follow: accessing sqldf is not the issue . also: what is fn here? Commented Jun 25, 2018 at 4:31
  • would this work fn$sqldf(paste0('select cid, count(1) cnt from clusts$clust',x,' group by cid order by 2 desc')) Commented Jun 25, 2018 at 4:37

1 Answer 1

2

Use the envir= argument of sqldf like this:

sqldf("select * from clust1", envir = list2env(clusts))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.